blob: 457dcc40a607ce2a38a968c44a1b2b68802ab609 [file] [log] [blame]
Mathias Agopian8ae23352009-06-04 13:53:57 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080017#include <androidfw/BackupHelpers.h>
Joe Onorato3ad977b2009-05-05 11:50:51 -070018
19#include <stdio.h>
20#include <string.h>
21
Joe Onorato4535e402009-05-15 09:07:06 -040022using namespace android;
23
Joe Onoratoc825d3e2009-05-06 12:55:46 -040024#if TEST_BACKUP_HELPERS
Joe Onorato3ad977b2009-05-05 11:50:51 -070025
26// ============================================================
27// ============================================================
28typedef int (*test_func)();
29
30struct Test {
31 const char* name;
32 test_func func;
33 int result;
34 bool run;
35};
36
37Test TESTS[] = {
38 { "backup_helper_test_empty", backup_helper_test_empty, 0, false },
39 { "backup_helper_test_four", backup_helper_test_four, 0, false },
40 { "backup_helper_test_files", backup_helper_test_files, 0, false },
Joe Onorato23ecae32009-06-10 17:07:15 -070041 { "backup_helper_test_null_base", backup_helper_test_null_base, 0, false },
Joe Onoratoce88cb12009-06-11 11:27:16 -070042 { "backup_helper_test_missing_file", backup_helper_test_missing_file, 0, false },
Joe Onorato4535e402009-05-15 09:07:06 -040043 { "backup_helper_test_data_writer", backup_helper_test_data_writer, 0, false },
Joe Onorato2e1da322009-05-15 18:20:19 -040044 { "backup_helper_test_data_reader", backup_helper_test_data_reader, 0, false },
Joe Onorato3ad977b2009-05-05 11:50:51 -070045 { 0, NULL, 0, false}
46};
47
48int
49main(int argc, const char** argv)
50{
51 Test* t;
52
53 if (argc == 1) {
54 t = TESTS;
55 while (t->name) {
56 t->run = true;
57 t++;
58 }
59 } else {
60 t = TESTS;
61 while (t->name) {
62 for (int i=1; i<argc; i++) {
63 if (0 == strcmp(t->name, argv[i])) {
64 t->run = true;
65 }
66 }
67 t++;
68 }
69 }
70
71 int testCount = 0;
72 t = TESTS;
73 while (t->name) {
74 if (t->run) {
75 testCount++;
76 }
77 t++;
78 }
79
80
81 int failed = 0;
82 int i = 1;
83 t = TESTS;
84 while (t->name) {
85 if (t->run) {
86 printf("===== Running %s (%d of %d) ==============================\n",
87 t->name, i, testCount);
88 fflush(stdout);
89 fflush(stderr);
90 t->result = t->func();
91 if (t->result != 0) {
92 failed++;
93 printf("failed\n");
94 } else {
95 printf("passed\n");
96 }
97 i++;
98 }
99 t++;
100 }
101
102 printf("=================================================================\n");
103 if (failed == 0) {
104 printf("All %d test(s) passed\n", testCount);
105 } else {
106 printf("Tests failed: (%d of %d)\n", failed, testCount);
107 t = TESTS;
108 while (t->name) {
109 if (t->run) {
110 if (t->result != 0) {
111 printf(" %s\n", t->name);
112 }
113 }
114 t++;
115 }
116 }
117}
Joe Onoratoc825d3e2009-05-06 12:55:46 -0400118
119#else
120int
Chih-Hung Hsiehb40ec902017-12-05 09:56:46 -0800121main(int, char**)
Joe Onoratoc825d3e2009-05-06 12:55:46 -0400122{
123 printf ("test_backup_helper built without the tests\n");
124 return 0;
125}
126#endif