| 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) 2013 - 2014 Aleksander Morgado <[email protected]> |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <config.h> |
| 8 |
|
| 9 |
#include "mbim-uuid.h" |
| 10 |
|
| 11 |
static void |
| 12 |
compare_uuid_strings (const MbimUuid *uuid, |
| 13 |
const gchar *other_uuid_str) |
| 14 |
{ |
| 15 |
gchar *uuid_str; |
| 16 |
|
| 17 |
uuid_str = mbim_uuid_get_printable (uuid); |
| 18 |
g_assert_cmpstr (uuid_str, ==, other_uuid_str); |
| 19 |
g_free (uuid_str); |
| 20 |
} |
| 21 |
|
| 22 |
static void |
| 23 |
test_uuid_basic_connect (void) |
| 24 |
{ |
| 25 |
compare_uuid_strings (MBIM_UUID_BASIC_CONNECT, |
| 26 |
"a289cc33-bcbb-8b4f-b6b0-133ec2aae6df"); |
| 27 |
} |
| 28 |
|
| 29 |
static void |
| 30 |
test_uuid_sms (void) |
| 31 |
{ |
| 32 |
compare_uuid_strings (MBIM_UUID_SMS, |
| 33 |
"533fbeeb-14fe-4467-9f90-33a223e56c3f"); |
| 34 |
} |
| 35 |
|
| 36 |
static void |
| 37 |
test_uuid_ussd (void) |
| 38 |
{ |
| 39 |
compare_uuid_strings (MBIM_UUID_USSD, |
| 40 |
"e550a0c8-5e82-479e-82f7-10abf4c3351f"); |
| 41 |
} |
| 42 |
|
| 43 |
static void |
| 44 |
test_uuid_phonebook (void) |
| 45 |
{ |
| 46 |
compare_uuid_strings (MBIM_UUID_PHONEBOOK, |
| 47 |
"4bf38476-1e6a-41db-b1d8-bed289c25bdb"); |
| 48 |
} |
| 49 |
|
| 50 |
static void |
| 51 |
test_uuid_stk (void) |
| 52 |
{ |
| 53 |
compare_uuid_strings (MBIM_UUID_STK, |
| 54 |
"d8f20131-fcb5-4e17-8602-d6ed3816164c"); |
| 55 |
} |
| 56 |
|
| 57 |
static void |
| 58 |
test_uuid_auth (void) |
| 59 |
{ |
| 60 |
compare_uuid_strings (MBIM_UUID_AUTH, |
| 61 |
"1d2b5ff7-0aa1-48b2-aa52-50f15767174e"); |
| 62 |
} |
| 63 |
|
| 64 |
static void |
| 65 |
test_uuid_dss (void) |
| 66 |
{ |
| 67 |
compare_uuid_strings (MBIM_UUID_DSS, |
| 68 |
"c08a26dd-7718-4382-8482-6e0d583c4d0e"); |
| 69 |
} |
| 70 |
|
| 71 |
static void |
| 72 |
test_uuid_ms_firmware_id (void) |
| 73 |
{ |
| 74 |
compare_uuid_strings (MBIM_UUID_MS_FIRMWARE_ID, |
| 75 |
"e9f7dea2-feaf-4009-93ce-90a3694103b6"); |
| 76 |
} |
| 77 |
|
| 78 |
static void |
| 79 |
test_uuid_ms_host_shutdown (void) |
| 80 |
{ |
| 81 |
compare_uuid_strings (MBIM_UUID_MS_HOST_SHUTDOWN, |
| 82 |
"883b7c26-985f-43fa-9804-27d7fb80959c"); |
| 83 |
} |
| 84 |
|
| 85 |
static void |
| 86 |
test_uuid_ms_sar (void) |
| 87 |
{ |
| 88 |
compare_uuid_strings (MBIM_UUID_MS_SAR, |
| 89 |
"68223d04-9f6c-4e0f-822d-28441fb72340"); |
| 90 |
} |
| 91 |
|
| 92 |
static void |
| 93 |
test_uuid_intel_firmware_update (void) |
| 94 |
{ |
| 95 |
compare_uuid_strings (MBIM_UUID_INTEL_FIRMWARE_UPDATE, |
| 96 |
"0ed374cb-f835-4474-bc11-3b3fd76f5641"); |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
test_uuid_ms_basic_connect_extensions (void) |
| 101 |
{ |
| 102 |
compare_uuid_strings (MBIM_UUID_MS_BASIC_CONNECT_EXTENSIONS, |
| 103 |
"3d01dcc5-fef5-4d05-0d3a-bef7058e9aaf"); |
| 104 |
} |
| 105 |
|
| 106 |
static void |
| 107 |
test_uuid_quectel (void) |
| 108 |
{ |
| 109 |
compare_uuid_strings (MBIM_UUID_QUECTEL, |
| 110 |
"11223344-5566-7788-99aa-bbccddeeff11"); |
| 111 |
} |
| 112 |
|
| 113 |
/*****************************************************************************/ |
| 114 |
|
| 115 |
static void |
| 116 |
compare_uuid_types (const gchar *uuid_str, |
| 117 |
const MbimUuid *other_uuid) |
| 118 |
{ |
| 119 |
MbimUuid uuid; |
| 120 |
|
| 121 |
g_assert (mbim_uuid_from_printable (uuid_str, &uuid)); |
| 122 |
g_assert (mbim_uuid_cmp (&uuid, other_uuid)); |
| 123 |
} |
| 124 |
|
| 125 |
static void |
| 126 |
invalid_uuid_str (const gchar *uuid_str) |
| 127 |
{ |
| 128 |
MbimUuid uuid; |
| 129 |
|
| 130 |
g_assert (mbim_uuid_from_printable (uuid_str, &uuid) == FALSE); |
| 131 |
} |
| 132 |
|
| 133 |
static void |
| 134 |
test_uuid_valid (void) |
| 135 |
{ |
| 136 |
compare_uuid_types ("a289cc33-bcbb-8b4f-b6b0-133ec2aae6df", |
| 137 |
MBIM_UUID_BASIC_CONNECT); |
| 138 |
} |
| 139 |
|
| 140 |
static void |
| 141 |
test_uuid_valid_camelcase (void) |
| 142 |
{ |
| 143 |
compare_uuid_types ("A289cC33-BcBb-8B4f-B6b0-133Ec2Aae6Df", |
| 144 |
MBIM_UUID_BASIC_CONNECT); |
| 145 |
} |
| 146 |
|
| 147 |
static void |
| 148 |
test_uuid_invalid_empty (void) |
| 149 |
{ |
| 150 |
invalid_uuid_str (""); |
| 151 |
} |
| 152 |
|
| 153 |
static void |
| 154 |
test_uuid_invalid_short (void) |
| 155 |
{ |
| 156 |
invalid_uuid_str ("a289cc33-bcbb-8b4f-b6b0-"); |
| 157 |
} |
| 158 |
|
| 159 |
static void |
| 160 |
test_uuid_invalid_long (void) |
| 161 |
{ |
| 162 |
invalid_uuid_str ("a289cc33-bcbb-8b4f-b6b0-133ec2aae6dfaaa"); |
| 163 |
} |
| 164 |
|
| 165 |
static void |
| 166 |
test_uuid_invalid_dashes (void) |
| 167 |
{ |
| 168 |
/* Dashes one too early */ |
| 169 |
invalid_uuid_str ("289cc33-bcbb-8b4f-b6b0-133ec2aae6dfa"); |
| 170 |
} |
| 171 |
|
| 172 |
static void |
| 173 |
test_uuid_invalid_no_hex (void) |
| 174 |
{ |
| 175 |
invalid_uuid_str ("hello wo-rld -8b4f-b6b0-133ec2aae6df"); |
| 176 |
} |
| 177 |
|
| 178 |
/*****************************************************************************/ |
| 179 |
|
| 180 |
static void |
| 181 |
test_uuid_custom (void) |
| 182 |
{ |
| 183 |
static const gchar *nick = "register_custom"; |
| 184 |
static const MbimUuid uuid_custom = { |
| 185 |
.a = { 0x52, 0x65, 0x67, 0x69 }, |
| 186 |
.b = { 0x73, 0x74 }, |
| 187 |
.c = { 0x65, 0x72 }, |
| 188 |
.d = { 0x20, 0x63 }, |
| 189 |
.e = { 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x21 } |
| 190 |
}; |
| 191 |
guint service; |
| 192 |
|
| 193 |
/* SERVICE_AUTH is not a custom service */ |
| 194 |
g_assert (!mbim_service_id_is_custom (MBIM_SERVICE_AUTH)); |
| 195 |
|
| 196 |
service = mbim_register_custom_service (&uuid_custom, nick); |
| 197 |
g_assert (mbim_service_id_is_custom (service)); |
| 198 |
g_assert (g_strcmp0 (mbim_service_lookup_name (service), nick) == 0); |
| 199 |
g_assert (mbim_uuid_cmp (mbim_uuid_from_service (service), &uuid_custom)); |
| 200 |
g_assert (mbim_uuid_to_service (&uuid_custom) == service); |
| 201 |
g_assert (mbim_unregister_custom_service (service)); |
| 202 |
|
| 203 |
/* once removed service is not custom */ |
| 204 |
g_assert (!mbim_service_id_is_custom (service)); |
| 205 |
} |
| 206 |
|
| 207 |
/*****************************************************************************/ |
| 208 |
|
| 209 |
int main (int argc, char **argv) |
| 210 |
{ |
| 211 |
g_test_init (&argc, &argv, NULL); |
| 212 |
|
| 213 |
g_test_add_func ("/libmbim-glib/uuid/basic-connect", test_uuid_basic_connect); |
| 214 |
g_test_add_func ("/libmbim-glib/uuid/sms", test_uuid_sms); |
| 215 |
g_test_add_func ("/libmbim-glib/uuid/ussd", test_uuid_ussd); |
| 216 |
g_test_add_func ("/libmbim-glib/uuid/phonebook", test_uuid_phonebook); |
| 217 |
g_test_add_func ("/libmbim-glib/uuid/stk", test_uuid_stk); |
| 218 |
g_test_add_func ("/libmbim-glib/uuid/auth", test_uuid_auth); |
| 219 |
g_test_add_func ("/libmbim-glib/uuid/dss", test_uuid_dss); |
| 220 |
g_test_add_func ("/libmbim-glib/uuid/ms-firmware-id", test_uuid_ms_firmware_id); |
| 221 |
g_test_add_func ("/libmbim-glib/uuid/ms-host-shutdown", test_uuid_ms_host_shutdown); |
| 222 |
g_test_add_func ("/libmbim-glib/uuid/ms-sar", test_uuid_ms_sar); |
| 223 |
g_test_add_func ("/libmbim-glib/uuid/intel-firmware-update", test_uuid_intel_firmware_update); |
| 224 |
g_test_add_func ("/libmbim-glib/uuid/ms-basic-connect-extensions", test_uuid_ms_basic_connect_extensions); |
| 225 |
g_test_add_func ("/libmbim-glib/uuid/quectel", test_uuid_quectel); |
| 226 |
|
| 227 |
g_test_add_func ("/libmbim-glib/uuid/valid", test_uuid_valid); |
| 228 |
g_test_add_func ("/libmbim-glib/uuid/valid/camelcase", test_uuid_valid_camelcase); |
| 229 |
|
| 230 |
g_test_add_func ("/libmbim-glib/uuid/invalid/empty", test_uuid_invalid_empty); |
| 231 |
g_test_add_func ("/libmbim-glib/uuid/invalid/short", test_uuid_invalid_short); |
| 232 |
g_test_add_func ("/libmbim-glib/uuid/invalid/long", test_uuid_invalid_long); |
| 233 |
g_test_add_func ("/libmbim-glib/uuid/invalid/dashes", test_uuid_invalid_dashes); |
| 234 |
g_test_add_func ("/libmbim-glib/uuid/invalid/no-hex", test_uuid_invalid_no_hex); |
| 235 |
|
| 236 |
g_test_add_func ("/libmbim-glib/uuid/custom", test_uuid_custom); |
| 237 |
|
| 238 |
return g_test_run (); |
| 239 |
} |