Mathias Agopian | 8ae2335 | 2009-06-04 13:53:57 -0700 | [diff] [blame] | 1 | /* |
| 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 Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 17 | #include <androidfw/BackupHelpers.h> |
Joe Onorato | 3ad977b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <string.h> |
| 21 | |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 22 | using namespace android; |
| 23 | |
Joe Onorato | c825d3e | 2009-05-06 12:55:46 -0400 | [diff] [blame] | 24 | #if TEST_BACKUP_HELPERS |
Joe Onorato | 3ad977b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 25 | |
| 26 | // ============================================================ |
| 27 | // ============================================================ |
| 28 | typedef int (*test_func)(); |
| 29 | |
| 30 | struct Test { |
| 31 | const char* name; |
| 32 | test_func func; |
| 33 | int result; |
| 34 | bool run; |
| 35 | }; |
| 36 | |
| 37 | Test 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 Onorato | 23ecae3 | 2009-06-10 17:07:15 -0700 | [diff] [blame] | 41 | { "backup_helper_test_null_base", backup_helper_test_null_base, 0, false }, |
Joe Onorato | ce88cb1 | 2009-06-11 11:27:16 -0700 | [diff] [blame] | 42 | { "backup_helper_test_missing_file", backup_helper_test_missing_file, 0, false }, |
Joe Onorato | 4535e40 | 2009-05-15 09:07:06 -0400 | [diff] [blame] | 43 | { "backup_helper_test_data_writer", backup_helper_test_data_writer, 0, false }, |
Joe Onorato | 2e1da32 | 2009-05-15 18:20:19 -0400 | [diff] [blame] | 44 | { "backup_helper_test_data_reader", backup_helper_test_data_reader, 0, false }, |
Joe Onorato | 3ad977b | 2009-05-05 11:50:51 -0700 | [diff] [blame] | 45 | { 0, NULL, 0, false} |
| 46 | }; |
| 47 | |
| 48 | int |
| 49 | main(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 Onorato | c825d3e | 2009-05-06 12:55:46 -0400 | [diff] [blame] | 118 | |
| 119 | #else |
| 120 | int |
Chih-Hung Hsieh | b40ec90 | 2017-12-05 09:56:46 -0800 | [diff] [blame] | 121 | main(int, char**) |
Joe Onorato | c825d3e | 2009-05-06 12:55:46 -0400 | [diff] [blame] | 122 | { |
| 123 | printf ("test_backup_helper built without the tests\n"); |
| 124 | return 0; |
| 125 | } |
| 126 | #endif |