| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 3 |
/* |
| 4 |
* Copyright (C) 2017 Google Inc. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <config.h> |
| 8 |
|
| 9 |
#include "mbim-common.h" |
| 10 |
|
| 11 |
static void |
| 12 |
test_common_str_hex (void) |
| 13 |
{ |
| 14 |
static const guint8 buffer [] = { 0x00, 0xDE, 0xAD, 0xC0, 0xDE }; |
| 15 |
gchar *str; |
| 16 |
|
| 17 |
str = mbim_common_str_hex (NULL, 0, ':'); |
| 18 |
g_assert (str == NULL); |
| 19 |
|
| 20 |
str = mbim_common_str_hex (buffer, 0, ':'); |
| 21 |
g_assert (str == NULL); |
| 22 |
|
| 23 |
str = mbim_common_str_hex (buffer, 1, ':'); |
| 24 |
g_assert_cmpstr (str, ==, "00"); |
| 25 |
g_free (str); |
| 26 |
|
| 27 |
str = mbim_common_str_hex (buffer, 2, '-'); |
| 28 |
g_assert_cmpstr (str, ==, "00-DE"); |
| 29 |
g_free (str); |
| 30 |
|
| 31 |
str = mbim_common_str_hex (buffer, 5, '.'); |
| 32 |
g_assert_cmpstr (str, ==, "00.DE.AD.C0.DE"); |
| 33 |
g_free (str); |
| 34 |
} |
| 35 |
|
| 36 |
/*****************************************************************************/ |
| 37 |
|
| 38 |
int main (int argc, char **argv) |
| 39 |
{ |
| 40 |
g_test_init (&argc, &argv, NULL); |
| 41 |
|
| 42 |
g_test_add_func ("/common/str_hex", test_common_str_hex); |
| 43 |
|
| 44 |
return g_test_run (); |
| 45 |
} |