diff options
author | Joe Onorato <joeo@android.com> | 2009-05-05 11:50:51 -0700 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2009-05-05 13:45:25 -0700 |
commit | 3ad977b41c6e4ef30c2f4f316b909b742ffc04aa (patch) | |
tree | 0b3c7a5263817709bc31c19e02f9fbc19b63de82 /tests/backup | |
parent | 06d96020c35dac2bf1651cb8bd4cfced911f1142 (diff) | |
download | frameworks_base-3ad977b41c6e4ef30c2f4f316b909b742ffc04aa.zip frameworks_base-3ad977b41c6e4ef30c2f4f316b909b742ffc04aa.tar.gz frameworks_base-3ad977b41c6e4ef30c2f4f316b909b742ffc04aa.tar.bz2 |
Add some C++ code to do raw files for backup
Diffstat (limited to 'tests/backup')
-rw-r--r-- | tests/backup/Android.mk | 26 | ||||
-rw-r--r-- | tests/backup/backup_helper_test.cpp | 97 |
2 files changed, 123 insertions, 0 deletions
diff --git a/tests/backup/Android.mk b/tests/backup/Android.mk new file mode 100644 index 0000000..5586d1d --- /dev/null +++ b/tests/backup/Android.mk @@ -0,0 +1,26 @@ +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + backup_helper_test.cpp + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := backup_helper_test +LOCAL_SHARED_LIBRARIES := libutils + +include $(BUILD_EXECUTABLE) + diff --git a/tests/backup/backup_helper_test.cpp b/tests/backup/backup_helper_test.cpp new file mode 100644 index 0000000..a661729 --- /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++; + } + } +} |