1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
15 // This function tests the C implementation of tokenization API. These functions
16 // are called from the main C++ test file.
18 #include "pw_tokenizer/tokenize.h"
19 #include "pw_tokenizer_private/tokenize_test.h"
22 #error "This is a test of C code and must be compiled as C, not C++."
25 void pw_tokenizer_ToBufferTest_StringShortFloat(void* buffer,
26 size_t* buffer_size) {
28 PW_TOKENIZE_TO_BUFFER(
29 buffer, buffer_size, TEST_FORMAT_STRING_SHORT_FLOAT, str, (short)-2, 3.0);
32 // This test invokes the tokenization API with a variety of types. To simplify
33 // validating the encoded data, numbers that are sequential when zig-zag encoded
34 // are used as arguments.
35 void pw_tokenizer_ToBufferTest_SequentialZigZag(void* buffer,
36 size_t* buffer_size) {
37 PW_TOKENIZE_TO_BUFFER(buffer,
39 TEST_FORMAT_SEQUENTIAL_ZIG_ZAG,
56 void pw_tokenizer_ToCallbackTest_SequentialZigZag(
57 void (*callback)(const uint8_t* buffer, size_t size)) {
58 PW_TOKENIZE_TO_CALLBACK(callback,
59 TEST_FORMAT_SEQUENTIAL_ZIG_ZAG,
76 void pw_tokenizer_ToBufferTest_Requires8(void* buffer, size_t* buffer_size) {
77 PW_TOKENIZE_TO_BUFFER(buffer, buffer_size, TEST_FORMAT_REQUIRES_8, "hi", -7);