summaryrefslogtreecommitdiff
path: root/tests/backup/backup_helper_test.cpp
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2009-05-05 11:50:51 -0700
committerJoe Onorato <joeo@android.com>2009-05-05 13:45:25 -0700
commit3ad977b41c6e4ef30c2f4f316b909b742ffc04aa (patch)
tree0b3c7a5263817709bc31c19e02f9fbc19b63de82 /tests/backup/backup_helper_test.cpp
parent06d96020c35dac2bf1651cb8bd4cfced911f1142 (diff)
Add some C++ code to do raw files for backup
Diffstat (limited to 'tests/backup/backup_helper_test.cpp')
-rw-r--r--tests/backup/backup_helper_test.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/backup/backup_helper_test.cpp b/tests/backup/backup_helper_test.cpp
new file mode 100644
index 000000000000..a661729766f0
--- /dev/null
+++ b/tests/backup/backup_helper_test.cpp
@@ -0,0 +1,97 @@
+#include <utils/backup_helpers.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#if !(TEST_BACKUP_HELPERS)
+#error These tests require TEST_BACKUP_HELPERS to be defined.
+#endif
+
+// ============================================================
+// ============================================================
+typedef int (*test_func)();
+
+struct Test {
+ const char* name;
+ test_func func;
+ int result;
+ bool run;
+};
+
+Test TESTS[] = {
+ { "backup_helper_test_empty", backup_helper_test_empty, 0, false },
+ { "backup_helper_test_four", backup_helper_test_four, 0, false },
+ { "backup_helper_test_files", backup_helper_test_files, 0, false },
+ { 0, NULL, 0, false}
+};
+
+int
+main(int argc, const char** argv)
+{
+ Test* t;
+
+ if (argc == 1) {
+ t = TESTS;
+ while (t->name) {
+ t->run = true;
+ t++;
+ }
+ } else {
+ t = TESTS;
+ while (t->name) {
+ for (int i=1; i<argc; i++) {
+ if (0 == strcmp(t->name, argv[i])) {
+ t->run = true;
+ }
+ }
+ t++;
+ }
+ }
+
+ int testCount = 0;
+ t = TESTS;
+ while (t->name) {
+ if (t->run) {
+ testCount++;
+ }
+ t++;
+ }
+
+
+ int failed = 0;
+ int i = 1;
+ t = TESTS;
+ while (t->name) {
+ if (t->run) {
+ printf("===== Running %s (%d of %d) ==============================\n",
+ t->name, i, testCount);
+ fflush(stdout);
+ fflush(stderr);
+ t->result = t->func();
+ if (t->result != 0) {
+ failed++;
+ printf("failed\n");
+ } else {
+ printf("passed\n");
+ }
+ i++;
+ }
+ t++;
+ }
+
+ printf("=================================================================\n");
+ if (failed == 0) {
+ printf("All %d test(s) passed\n", testCount);
+ } else {
+ printf("Tests failed: (%d of %d)\n", failed, testCount);
+ t = TESTS;
+ while (t->name) {
+ if (t->run) {
+ if (t->result != 0) {
+ printf(" %s\n", t->name);
+ }
+ }
+ t++;
+ }
+ }
+}