blob: 04d555171e36ecd3c4275b2dc1d5f4c71fe8e701 [file] [log] [blame]
Wyatt Hepler6639c452020-05-06 11:43:07 -07001// Copyright 2020 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15// This function tests the C implementation of tokenization API. These functions
16// are called from the main C++ test file.
17
18#include "pw_tokenizer/tokenize_to_global_handler.h"
19#include "pw_tokenizer/tokenize_to_global_handler_with_payload.h"
20#include "pw_tokenizer_private/tokenize_test.h"
21
22#ifdef __cplusplus
23#error "This is a test of C code and must be compiled as C, not C++."
24#endif // __cplusplus
25
26// This test invokes the tokenization API with a variety of types. To simplify
27// validating the encoded data, numbers that are sequential when zig-zag encoded
28// are used as arguments.
Wyatt Hepler7a5e4d62020-08-31 08:39:16 -070029void pw_tokenizer_ToGlobalHandlerTest_SequentialZigZag(void) {
Wyatt Hepler6639c452020-05-06 11:43:07 -070030 PW_TOKENIZE_TO_GLOBAL_HANDLER(TEST_FORMAT_SEQUENTIAL_ZIG_ZAG,
31 0u,
32 -1,
33 1u,
34 (unsigned)-2,
35 (unsigned short)2u,
36 (signed char)-3,
37 3,
38 -4l,
39 4ul,
40 -5ll,
41 5ull,
42 (signed char)-6,
43 (char)6,
44 (signed char)-7);
45}
46
Wyatt Hepler7a5e4d62020-08-31 08:39:16 -070047void pw_tokenizer_ToGlobalHandlerWithPayloadTest_SequentialZigZag(void) {
48 PW_TOKENIZE_TO_GLOBAL_HANDLER_WITH_PAYLOAD((pw_tokenizer_Payload)600613,
Wyatt Hepler6639c452020-05-06 11:43:07 -070049 TEST_FORMAT_SEQUENTIAL_ZIG_ZAG,
50 0u,
51 -1,
52 1u,
53 (unsigned)-2,
54 (unsigned short)2u,
55 (signed char)-3,
56 3,
57 -4l,
58 4ul,
59 -5ll,
60 5ull,
61 (signed char)-6,
62 (char)6,
63 (signed char)-7);
64}