ON Semiconductor / mbed-os

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_libtrace.cpp Source File

test_libtrace.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 "test_libtrace.h"
00018 #include <string.h>
00019 #include "ip6tos_stub.h"
00020 
00021 char buf[1024];
00022 
00023 static void myprint(const char *str)
00024 {
00025     strcpy(buf, str);
00026 }
00027 
00028 Test_LibTrace::Test_LibTrace()
00029 {
00030     trace_init();
00031     set_trace_print_function(myprint);
00032 }
00033 
00034 Test_LibTrace::~Test_LibTrace()
00035 {
00036     trace_free();
00037 }
00038 
00039 void Test_LibTrace::test_libTrace_tracef()
00040 {
00041     set_trace_config(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
00042 
00043     memset(buf, 0, 1024);
00044     unsigned char longStr[1000] = {0x76};
00045     tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", trace_array(longStr, 1000));
00046     CHECK(buf[0] == '7');
00047 
00048     memset(buf, 0, 1024);
00049     const char longStr2[200] = {0x36};
00050     tracef(TRACE_LEVEL_DEBUG, "mygr", longStr2);
00051     CHECK(buf[0] == '6');
00052 
00053 
00054 }
00055 
00056 void Test_LibTrace::test_libTrace_trace_ipv6_prefix()
00057 {
00058     memset(buf, 0, 1024);
00059     uint8_t prefix[] = { 0x14, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 };
00060     int prefix_len = 64;
00061     ip6tos_stub.c = '7';
00062     ip6tos_stub.h = false;
00063     char *str = trace_ipv6_prefix(prefix, prefix_len);
00064     SimpleString ss(str);
00065 
00066     CHECK("/64" == ss);
00067 
00068     ip6tos_stub.h = true;
00069     char *str2 = trace_ipv6_prefix(prefix, prefix_len);
00070     SimpleString ss2(str2);
00071 
00072     CHECK("7/64" == ss2);
00073 }