1a8e1175bSopenharmony_ci/* BEGIN_HEADER */
2a8e1175bSopenharmony_ci#include "mbedtls/version.h"
3a8e1175bSopenharmony_ci/* END_HEADER */
4a8e1175bSopenharmony_ci
5a8e1175bSopenharmony_ci/* BEGIN_DEPENDENCIES
6a8e1175bSopenharmony_ci * depends_on:MBEDTLS_VERSION_C
7a8e1175bSopenharmony_ci * END_DEPENDENCIES
8a8e1175bSopenharmony_ci */
9a8e1175bSopenharmony_ci
10a8e1175bSopenharmony_ci/* BEGIN_CASE */
11a8e1175bSopenharmony_civoid check_compiletime_version(char *version_str)
12a8e1175bSopenharmony_ci{
13a8e1175bSopenharmony_ci    char build_str[100];
14a8e1175bSopenharmony_ci    char build_str_full[100];
15a8e1175bSopenharmony_ci    unsigned int build_int;
16a8e1175bSopenharmony_ci
17a8e1175bSopenharmony_ci    memset(build_str, 0, 100);
18a8e1175bSopenharmony_ci    memset(build_str_full, 0, 100);
19a8e1175bSopenharmony_ci
20a8e1175bSopenharmony_ci    mbedtls_snprintf(build_str, 100, "%d.%d.%d", MBEDTLS_VERSION_MAJOR,
21a8e1175bSopenharmony_ci                     MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH);
22a8e1175bSopenharmony_ci
23a8e1175bSopenharmony_ci    mbedtls_snprintf(build_str_full, 100, "mbed TLS %d.%d.%d", MBEDTLS_VERSION_MAJOR,
24a8e1175bSopenharmony_ci                     MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH);
25a8e1175bSopenharmony_ci
26a8e1175bSopenharmony_ci    build_int = MBEDTLS_VERSION_MAJOR << 24 |
27a8e1175bSopenharmony_ci                MBEDTLS_VERSION_MINOR << 16 |
28a8e1175bSopenharmony_ci                MBEDTLS_VERSION_PATCH << 8;
29a8e1175bSopenharmony_ci
30a8e1175bSopenharmony_ci    TEST_ASSERT(build_int == MBEDTLS_VERSION_NUMBER);
31a8e1175bSopenharmony_ci    TEST_ASSERT(strcmp(build_str, MBEDTLS_VERSION_STRING) == 0);
32a8e1175bSopenharmony_ci    TEST_ASSERT(strcmp(build_str_full, MBEDTLS_VERSION_STRING_FULL) == 0);
33a8e1175bSopenharmony_ci    TEST_ASSERT(strcmp(version_str, MBEDTLS_VERSION_STRING) == 0);
34a8e1175bSopenharmony_ci}
35a8e1175bSopenharmony_ci/* END_CASE */
36a8e1175bSopenharmony_ci
37a8e1175bSopenharmony_ci/* BEGIN_CASE */
38a8e1175bSopenharmony_civoid check_runtime_version(char *version_str)
39a8e1175bSopenharmony_ci{
40a8e1175bSopenharmony_ci    char build_str[100];
41a8e1175bSopenharmony_ci    char get_str[100];
42a8e1175bSopenharmony_ci    char build_str_full[100];
43a8e1175bSopenharmony_ci    char get_str_full[100];
44a8e1175bSopenharmony_ci    unsigned int get_int;
45a8e1175bSopenharmony_ci
46a8e1175bSopenharmony_ci    memset(build_str, 0, 100);
47a8e1175bSopenharmony_ci    memset(get_str, 0, 100);
48a8e1175bSopenharmony_ci    memset(build_str_full, 0, 100);
49a8e1175bSopenharmony_ci    memset(get_str_full, 0, 100);
50a8e1175bSopenharmony_ci
51a8e1175bSopenharmony_ci    get_int = mbedtls_version_get_number();
52a8e1175bSopenharmony_ci    mbedtls_version_get_string(get_str);
53a8e1175bSopenharmony_ci    mbedtls_version_get_string_full(get_str_full);
54a8e1175bSopenharmony_ci
55a8e1175bSopenharmony_ci    mbedtls_snprintf(build_str, 100, "%u.%u.%u",
56a8e1175bSopenharmony_ci                     (get_int >> 24) & 0xFF,
57a8e1175bSopenharmony_ci                     (get_int >> 16) & 0xFF,
58a8e1175bSopenharmony_ci                     (get_int >> 8) & 0xFF);
59a8e1175bSopenharmony_ci    mbedtls_snprintf(build_str_full, 100, "mbed TLS %s", version_str);
60a8e1175bSopenharmony_ci
61a8e1175bSopenharmony_ci    TEST_ASSERT(strcmp(build_str, version_str) == 0);
62a8e1175bSopenharmony_ci    TEST_ASSERT(strcmp(build_str_full, get_str_full) == 0);
63a8e1175bSopenharmony_ci    TEST_ASSERT(strcmp(version_str, get_str) == 0);
64a8e1175bSopenharmony_ci}
65a8e1175bSopenharmony_ci/* END_CASE */
66a8e1175bSopenharmony_ci
67a8e1175bSopenharmony_ci/* BEGIN_CASE depends_on:MBEDTLS_VERSION_FEATURES */
68a8e1175bSopenharmony_civoid check_feature(char *feature, int result)
69a8e1175bSopenharmony_ci{
70a8e1175bSopenharmony_ci    int check = mbedtls_version_check_feature(feature);
71a8e1175bSopenharmony_ci    TEST_ASSERT(check == result);
72a8e1175bSopenharmony_ci}
73a8e1175bSopenharmony_ci/* END_CASE */
74