Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ip6tos_test.cpp Source File

ip6tos_test.cpp

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "CppUTest/TestHarness.h"
00017 #include "ip6string.h"
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <stdint.h>
00021 
00022 TEST_GROUP(ip6tos)
00023 {
00024     void setup() {
00025     }
00026 
00027     void teardown() {
00028     }
00029 };
00030 
00031 TEST(ip6tos, ip6_prefix_tos_func)
00032 {
00033     char prefix_str[45] = {0};
00034     char str_len = 0;
00035     char *expected;
00036 
00037     uint8_t prefix[] = { 0x14, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 };
00038     int prefix_len = 64;
00039     expected = "146e:a00::/64";
00040     str_len = ip6_prefix_tos(prefix, prefix_len, prefix_str);
00041     CHECK(str_len == 13);
00042     STRCMP_EQUAL(expected, prefix_str);
00043 
00044     memset(prefix_str, 0, 45);
00045     str_len = 0;
00046     expected = "::/0";
00047     str_len = ip6_prefix_tos(NULL, 0, prefix_str);
00048     CHECK(str_len == 4);
00049     STRCMP_EQUAL(expected, prefix_str);
00050 
00051     str_len = 0;
00052     uint8_t prefix_2[16];
00053     memset(prefix_2, 0x88, 16);
00054     expected = "8888:8888:8888:8888:8888:8888:8888:8888/128";
00055     str_len = ip6_prefix_tos(prefix_2, 128, prefix_str);
00056     CHECK(str_len == 43);
00057     STRCMP_EQUAL(expected, prefix_str);
00058 
00059     memset(prefix_str, 0, 45);
00060     str_len = ip6_prefix_tos(prefix, 130, prefix_str);
00061     CHECK(str_len == 0);
00062 }
00063 
00064 /***********************************************************/
00065 /* Second test group for the old tests that were once lost */
00066 
00067 const char string_addr[][40] = {
00068     "2001:db8::1:0:0:1",                    // 1
00069     "2001:db8:aaaa:bbbb:cccc:dddd:eeee:1",  // 2
00070     "2001:db8::1",                          // 3
00071     "2001:db8::2:1",                        // 4
00072     "2001:db8:aaaa:bbbb:cccc:dddd:0:1",     // 5
00073     "2001:db8::aaaa:0:0:1",                 // 6
00074     "2001:0:0:1::1",                        // 7
00075     "2001:0:0:1::",                         // 8
00076     "2001:db8::",                           // 9
00077     "::aaaa:0:0:1",                         // 10
00078     "::1",                                  // 11
00079     "::",                                   // 12
00080 };
00081 
00082 
00083 const uint8_t hex_addr[][16] = {
00084     { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
00085     { 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
00086     { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
00087     { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 },
00088     { 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 },
00089     { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
00090     { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
00091     { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
00092     { 0x20, 0x01, 0xd, 0xb8 },
00093     { 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
00094     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
00095     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
00096 };
00097 
00098 char buf[40];
00099 int i = 0;
00100 
00101 TEST_GROUP(ip6tos_2)
00102 {
00103     void setUp(void) {
00104         memset(buf, 0, 40);
00105     }
00106 
00107     void tearDown(void) {
00108         i++;
00109     }
00110 };
00111 
00112 TEST(ip6tos_2, test_1)
00113 {
00114     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00115     STRCMP_EQUAL(string_addr[i], buf);
00116 }
00117 
00118 TEST(ip6tos_2, test_2)
00119 {
00120     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00121     STRCMP_EQUAL(string_addr[i], buf);
00122 }
00123 TEST(ip6tos_2, test_3)
00124 {
00125     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00126     STRCMP_EQUAL(string_addr[i], buf);
00127 }
00128 TEST(ip6tos_2, test_4)
00129 {
00130     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00131     STRCMP_EQUAL(string_addr[i], buf);
00132 }
00133 TEST(ip6tos_2, test_5)
00134 {
00135     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00136     STRCMP_EQUAL(string_addr[i], buf);
00137 }
00138 TEST(ip6tos_2, test_6)
00139 {
00140     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00141     STRCMP_EQUAL(string_addr[i], buf);
00142 }
00143 TEST(ip6tos_2, test_7)
00144 {
00145     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00146     STRCMP_EQUAL(string_addr[i], buf);
00147 }
00148 TEST(ip6tos_2, test_8)
00149 {
00150     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00151     STRCMP_EQUAL(string_addr[i], buf);
00152 }
00153 TEST(ip6tos_2, test_9)
00154 {
00155     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00156     STRCMP_EQUAL(string_addr[i], buf);
00157 }
00158 TEST(ip6tos_2, test_10)
00159 {
00160     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00161     STRCMP_EQUAL(string_addr[i], buf);
00162 }
00163 TEST(ip6tos_2, test_11)
00164 {
00165     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00166     STRCMP_EQUAL(string_addr[i], buf);
00167 }
00168 TEST(ip6tos_2, test_12)
00169 {
00170     CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf));
00171     STRCMP_EQUAL(string_addr[i], buf);
00172 }