1 /* 2 * Copyright (C) 2008 Esmertec AG. 3 * Copyright (C) 2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #include <embUnit.h> 19 #include <stdlib.h> 20 #include <string.h> 21 #include "wbxml_parser.h" 22 23 #define DEFINE_TEST(test) \ 24 new_TestFixture( #test, test) 25 26 #define ASSERT_EQUAL_INT(expected, actual) \ 27 { \ 28 int tmp = actual; /* avoid duplicated evaluation in TEST_ASSERT_EQUAL_INT */ \ 29 TEST_ASSERT_EQUAL_INT(expected, tmp); \ 30 } 31 32 /* 33 <?xml version="1.0" encoding="UTF-8" ?> 34 -//SYNCML//DTD SyncML 1.2//EN 35 */ 36 static const char incomplete_array[] = { 37 0x02, 0x00, 0x00, 0x6A, 0x1E, '-', '/', '/', 'S', 'Y', 38 'N', 'C', 'M', 'L', '/', '/', 'D', 'T', 'D', ' ', 'S', 39 'y', 'n', 'c', 'M', 'L', ' ', '1', '.', '2', '/', '/', 40 'E', 'N', 0x00, 0x01 41 }; 42 43 static const char complete_array_scts[] = { 44 0x02, 0x00, 0x00, 0x6a, 0x1e, 0x2d, 0x2f, 0x2f, 0x53, 45 0x59, 0x4e, 0x43, 0x4d, 0x4c, 0x2f, 0x2f, 0x44, 0x54, 46 0x44, 0x20, 0x53, 0x79, 0x6e, 0x63, 0x4d, 0x4c, 0x20, 47 0x31, 0x2e, 0x31, 0x2f, 0x2f, 0x45, 0x4e, 0x00, 0x6d, 48 0x6c, 0x71, 0x03, 0x31, 0x2e, 0x31, 0x00, 0x01, 0x72, 49 0x03, 0x53, 0x79, 0x6e, 0x63, 0x4d, 0x4c, 0x2f, 0x31, 50 0x2e, 0x31, 0x00, 0x01, 0x65, 0x03, 0x34, 0x00, 0x01, 51 0x5b, 0x03, 0x32, 0x00, 0x01, 0x6e, 0x57, 0x03, 0x68, 52 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x30, 0x2e, 53 0x31, 0x35, 0x2e, 0x31, 0x31, 0x2e, 0x32, 0x35, 0x34, 54 0x2f, 0x53, 0x63, 0x74, 0x73, 0x3f, 0x51, 0x4e, 0x41, 55 0x35, 0x41, 0x41, 0x3d, 0x3d, 0x00, 0x01, 0x01, 0x67, 56 0x57, 0x03, 0x53, 0x59, 0x4e, 0x43, 0x4d, 0x4c, 0x3a, 57 0x31, 0x00, 0x01, 0x01, 0x4e, 0x5a, 0x00, 0x01, 0x47, 58 0x03, 0x62, 0x36, 0x34, 0x00, 0x01, 0x53, 0x03, 0x73, 59 0x79, 0x6e, 0x63, 0x6d, 0x6c, 0x3a, 0x61, 0x75, 0x74, 60 0x68, 0x2d, 0x62, 0x61, 0x73, 0x69, 0x63, 0x00, 0x01, 61 0x01, 0x00, 0x00, 0x4f, 0x03, 0x63, 0x32, 0x56, 0x79, 62 0x64, 0x6d, 0x56, 0x79, 0x4f, 0x6e, 0x4e, 0x6c, 0x63, 63 0x6e, 0x5a, 0x6c, 0x63, 0x67, 0x3d, 0x3d, 0x00, 0x01, 64 0x01, 0x5a, 0x00, 0x01, 0x4c, 0x03, 0x32, 0x30, 0x30, 65 0x30, 0x30, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x6b, 66 0x69, 0x4b, 0x03, 0x31, 0x00, 0x01, 0x5c, 0x03, 0x31, 67 0x00, 0x01, 0x4c, 0x03, 0x30, 0x00, 0x01, 0x4a, 0x03, 68 0x53, 0x79, 0x6e, 0x63, 0x48, 0x64, 0x72, 0x00, 0x01, 69 0x6f, 0x03, 0x53, 0x59, 0x4e, 0x43, 0x4d, 0x4c, 0x3a, 70 0x31, 0x00, 0x01, 0x68, 0x03, 0x68, 0x74, 0x74, 0x70, 71 0x3a, 0x2f, 0x2f, 0x31, 0x30, 0x2e, 0x31, 0x35, 0x2e, 72 0x31, 0x31, 0x2e, 0x32, 0x35, 0x34, 0x2f, 0x53, 0x79, 73 0x6e, 0x63, 0x00, 0x01, 0x4f, 0x03, 0x32, 0x31, 0x32, 74 0x00, 0x01, 0x01, 0x46, 0x4b, 0x03, 0x32, 0x00, 0x01, 75 0x4f, 0x03, 0x32, 0x30, 0x30, 0x00, 0x01, 0x54, 0x6e, 76 0x57, 0x03, 0x64, 0x62, 0x00, 0x01, 0x01, 0x67, 0x57, 77 0x03, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x63, 0x74, 0x73, 78 0x00, 0x01, 0x01, 0x5a, 0x00, 0x01, 0x45, 0x4a, 0x03, 79 0x32, 0x30, 0x30, 0x38, 0x30, 0x31, 0x31, 0x37, 0x54, 80 0x30, 0x33, 0x30, 0x38, 0x32, 0x34, 0x5a, 0x00, 0x01, 81 0x4f, 0x03, 0x32, 0x30, 0x30, 0x38, 0x30, 0x31, 0x31, 82 0x37, 0x54, 0x30, 0x33, 0x31, 0x31, 0x31, 0x33, 0x5a, 83 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x12, 84 0x01, 0x01 85 }; 86 87 static const char complete_array2[] = { 88 0x02, 0x00, 0x00, 0x6A, 0x1E, '-', '/', '/', 'S', 'Y', 89 'N', 'C', 'M', 'L', '/', '/', 'D', 'T', 'D', ' ', 'S', 90 'y', 'n', 'c', 'M', 'L', ' ', '1', '.', '2', '/', '/', 91 'E', 'N', 0x00, 0x6D, 0x6C, 0x71, 0xC3, 0x03, '1', '.', 92 '2', 0x01, 0x72, 0xC3, 0x0A, 'S', 'y', 'n', 'c', 'M', 93 'L', '/', '1', '.', '2', 0x01, 0x65, 0xC3, 0x01, '1', 94 0x01, 0x5B, 0xC3, 0x01, '2', 0x01, 0x6E, 0x57, 0xC3, 95 0x20, 'h', 't', 't', 'p', ':', '/', '/', 'w', 'w', 'w', 96 '1', '.', 'd', 'a', 't', 'a', 's', 'y', 'n', 'c', '.', 97 'o', 'r', 'g', '/', 's', 'e', 'r', 'v', 'l', 'e', 't', 98 0x01, 0x01, 0x67, 0x57, 0xC3, 0x12, 'I', 'M', 'E', 'I', 99 ':', '1', '5', '6', '4', '4', '6', '9', '2', '1', '0', 100 '9', '4', '8', 0x01, 0x01, 0x01, 0x6B, 0x69, 0x4B, 101 0xC3, 0x01, '1', 0x01, 0x5C, 0xC3, 0x01, '1', 0x01, 102 0x4C, 0xC3, 0x01, '0', 0x01, 0x4A, 0xC3, 0x07, 'S', 103 'y', 'n', 'c', 'H', 'd', 'r', 0x01, 0x6F, 0xC3, 0x12, 104 'I', 'M', 'E', 'I', ':', '1', '5', '6', '4', '4', '6', 105 '9', '2', '1', '0', '9', '4', '8', 0x01, 0x68, 0xC3, 106 0x20, 'h', 't', 't', 'p', ':', '/', '/', 'w', 'w', 'w', 107 '1', '.', 'd', 'a', 't', 'a', 's', 'y', 'n', 'c', '.', 108 'o', 'r', 'g', '/', 's', 'e', 'r', 'v', 'l', 'e', 't', 109 0x01, 0x4F, 0xC3, 0x3, '2', '0', '0', 0x01, 0x01, 110 0x69, 0x4B, 0xC3, 0x01, '2', 0x01, 0x5C, 0xC3, 0x01, 111 '1', 0x01, 0x4C, 0xC3, 0x01, '1', 0x01, 0x4A, 0xC3, 112 0x05, 'A', 'l', 'e', 'r', 't', 0x01, 0x6F, 0xC3, 0x0E, 113 '.', '\\', 'd', 'e', 'v', '-', 'c', 'a', 'l', 'e', 'n', 114 'd', 'a', 'r', 0x01, 0x68, 0xC3, 0x0A, '.', '/', 'c', 115 'a', 'l', 'e', 'n', 'd', 'a', 'r', 0x01, 0x4F, 0xC3, 116 0x03, '2', '0', '0', 0x01, 0x54, 0x4F, 0x00, 0x01, 117 0x4F, 0xC3, 0x11, '2', '0', '0', '0', '0', '5', '0', 118 '2', '2', 'T', '0', '9', '3', '2', '2', '3', 'Z', 119 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x6A, 0x4B, 0xC3, 120 0x01, '3', 0x01, 0x6E, 0x57, 0xC3, 0x0A, '.', '/', 121 'c', 'a', 'l', 'e', 'n', 'd', 'a', 'r', 0x01, 0x01, 122 0x67, 0x57, 0xC3, 0x0E, '.', '\\', 'd', 'e', 'v', '-', 123 'c', 'a', 'l', 'e', 'n', 'd', 'a', 'r', 0x01, 0x01, 124 0x33, 0xC3, 0x01, '1', 0x01, 0x60, 0x4B, 0xC3, 0x01, 125 '4', 0x01, 0x5A, 0x00, 0x01, 0x4D, 0x03, 't', 'e', 'x', 126 't', '/', 'x', '-', 'v', 'c', 'a', 'l', 'e', 'n', 'd', 127 'a', 'r', 0x00, 0x01, 0x00, 0x00, 0x01, 0x54, 0x67, 128 0x57, 0xC3, 0x02, '2', '6', 0x01, 0x01, 0x4F, 0xC3, 129 0x04, 'C', 'A', 'L', '1', 0x01, 0x01, 0x01, 0x01, 0x12, 130 0x01, 0x01, 0x01 131 }; 132 133 static void setUp(void) 134 { 135 } 136 137 static void tearDown(void) 138 { 139 } 140 141 static void testSyncmlIncomplete(void) 142 { 143 WbxmlParser parser(0); 144 ASSERT_EQUAL_INT(WBXML_STATUS_ERROR, 145 parser.parse(incomplete_array, sizeof(incomplete_array), true)); 146 } 147 148 static void testSyncmlComplete(void) 149 { 150 WbxmlParser parser(0); 151 ASSERT_EQUAL_INT(WBXML_STATUS_OK, 152 parser.parse(complete_array_scts, sizeof(complete_array_scts), true)); 153 } 154 155 static void testSyncmlComplete2(void) 156 { 157 WbxmlParser parser(0); 158 ASSERT_EQUAL_INT(WBXML_STATUS_OK, 159 parser.parse(complete_array2, sizeof(complete_array2), true)); 160 } 161 162 extern "C" TestRef SyncmlParserTest_tests(void) 163 { 164 EMB_UNIT_TESTFIXTURES(fixtures) { 165 DEFINE_TEST(testSyncmlIncomplete), 166 DEFINE_TEST(testSyncmlComplete), 167 DEFINE_TEST(testSyncmlComplete2), 168 }; 169 EMB_UNIT_TESTCALLER(SyncmlParserTest, "SyncmlParserTest", setUp, tearDown, fixtures); 170 171 // temporary work around for the linker/loader problem of the sooner build 172 static TestCaller t = SyncmlParserTest; 173 t.isa = (TestImplement *) & TestCallerImplement; 174 return (TestRef) & t; 175 } 176