Debian Codegraph @

crt/s2n/tests/unit/s2n_utils_test.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include "s2n_test.h"
17 #include "testlib/s2n_testlib.h"
18 #include "utils/s2n_blob.h"
19 #include "utils/s2n_safety.h"
20
21 #define test_stack_blob_success(test_name, macro_name, requested, max) \
22 int test_name() \
23 { \
24 macro_name(test_name##blob, requested, max); \
25 POSIX_ENSURE_EQ(test_name##blob.size, requested); \
26 return 0; \
27 }
28
29 test_stack_blob_success(success_equal, s2n_stack_blob, 10, 10)
30
31 test_stack_blob_success(success_equal_smaller, s2n_stack_blob, 10, 100)
32
33 int requested_bigger_than_max()
34 {
35 s2n_stack_blob(foo, 11, 10);
36 /* This should never be reached due to the above failure */
37 POSIX_ENSURE_EQ(foo.allocated, 0);
38
39 return 0;
40 }
41
42 int successful_stack_blob()
43 {
44 s2n_stack_blob(foo, 10, 10);
45 POSIX_ENSURE_EQ(foo.size, 10);
46 POSIX_ENSURE_EQ(foo.allocated, 0);
47
48 s2n_stack_blob(foo2, 1, 10);
49 POSIX_ENSURE_EQ(foo2.size, 1);
50 POSIX_ENSURE_EQ(foo2.allocated, 0);
51
52 return 0;
53 }
54
55 int main(int argc, char **argv)
56 {
57 BEGIN_TEST();
58 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
59 EXPECT_FAILURE(requested_bigger_than_max());
60 EXPECT_SUCCESS(successful_stack_blob());
61 END_TEST();
62 }