blob: 3ca71ba142b6874230c9965d765b2ce00a97df78 [file] [log] [blame]
E. Scott Daniels8c6756d2021-04-19 15:13:51 -04001// : vi ts=4 sw=4 noet :
2/*
3==================================================================================
4 Copyright (c) 2021 Nokia
5 Copyright (c) 2021 AT&T Intellectual Property.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18==================================================================================
19*/
20
21
22/*
23 Mnemonic: wrapper_static_test.c
24 Abstract: Unit test for the wrapper module in common.
25
26 Author: E. Scott Daniels
27 Date: 19 April 2020
28*/
29
30#include <wrapper.c>
31
32/*
33 Called by the test driver (main). Returns the number of errors found.
34*/
35static int wrapper_test( ) {
36 int errors = 0;
37 char* b;
38 int len;
39
40 b = rmr_get_consts(); // function that builds constant json string for python-like things
41
42 if( fail_if_equal( strlen( b ), 0, "wrapper buffer had nothing" ) ) {
43 return 1; // can't do any further checking
44 }
45
46 errors += fail_if_true( *b != '{', "first character in buffer not valid json" );
47 len = strlen( b ) - 1;
48 errors += fail_if_true( *(b+len) != '}', "last character in buffer not valid json" );
49 free( b );
50
51 b = build_sval( "foobar", "value", 1 );
52 errors += fail_if_equal( strlen( b ), 0, "build svalue with sep returned nil buffer" );
53 errors += fail_not_equal( strcmp( b, "\"foobar\": \"value\"," ), 0, "svalue result not the expected string" );
54
55 b = build_sval( "foobar", "value", 0 );
56 errors += fail_if_equal( strlen( b ), 0, "build svalue without sep returned nil buffer" );
57 errors += fail_not_equal( strcmp( b, "\"foobar\": \"value\"" ), 0, "svalue result without sep not the expected string" );
58
59
60 // -------------------------------------------------------------------------------------------------
61
62 return !!errors; // 1 or 0 regardless of count
63}