summaryrefslogtreecommitdiff
path: root/vendor/bandit/specs/util
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:55 +0100
committerBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:55 +0100
commit062cd07342edc2b003555e90dd2cee0514b9f64a (patch)
tree3c73893dae8a9380c9f24e9c5822c5ec6bf671d5 /vendor/bandit/specs/util
parentffee481435ac0afe3f9a5a3eb07b2f2a46467089 (diff)
Add BanditCpp 1.1.4 test harness
Diffstat (limited to 'vendor/bandit/specs/util')
-rw-r--r--vendor/bandit/specs/util/argv_helper.h62
-rw-r--r--vendor/bandit/specs/util/util.h6
2 files changed, 68 insertions, 0 deletions
diff --git a/vendor/bandit/specs/util/argv_helper.h b/vendor/bandit/specs/util/argv_helper.h
new file mode 100644
index 00000000..4e92e725
--- /dev/null
+++ b/vendor/bandit/specs/util/argv_helper.h
@@ -0,0 +1,62 @@
+#ifndef BANDIT_SPECS_ARGV_HELPER_H
+#define BANDIT_SPECS_ARGV_HELPER_H
+
+#include <string.h>
+
+namespace bandit { namespace specs { namespace util {
+
+ //
+ // main() is supposed to receive its arguments as a non const 'char* argv[]'.
+ // This is a pain to create for each test. It's a whole lot easier to create
+ // a 'const char* argv[]' construct.
+ //
+ // This class helps copy from 'const char**' to 'char**' and handle cleanup
+ // automatically.
+ //
+ struct argv_helper
+ {
+ argv_helper(int argc, const char* argv[])
+ : argc_(argc)
+ {
+ non_const_argv_ = new char*[argc];
+ for(int i=0; i < argc; i++)
+ {
+ std::string s(argv[i]);
+ non_const_argv_[i] = new char[s.size() + 1];
+ for(size_t c=0;c<s.size();c++)
+ {
+ non_const_argv_[i][c] = s[c];
+ }
+ non_const_argv_[i][s.size()] = 0;
+ }
+ }
+
+
+
+ ~argv_helper()
+ {
+ for(int i=0; i < argc_; i++)
+ {
+ delete[] non_const_argv_[i];
+ }
+
+ delete[] non_const_argv_;
+ }
+
+ char** argv()
+ {
+ return non_const_argv_;
+ }
+
+ int argc()
+ {
+ return argc_;
+ }
+
+ private:
+ int argc_;
+ char** non_const_argv_;
+ };
+
+}}}
+#endif
diff --git a/vendor/bandit/specs/util/util.h b/vendor/bandit/specs/util/util.h
new file mode 100644
index 00000000..7ed17dd8
--- /dev/null
+++ b/vendor/bandit/specs/util/util.h
@@ -0,0 +1,6 @@
+#ifndef BANDIT_SPECS_UTIL_H
+#define BANDIT_SPECS_UTIL_H
+
+#include "argv_helper.h"
+
+#endif