mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-23 22:42:37 +01:00
unit: Create unit test for SSID UTF8 pretty-printing
Write a set of tests that check correct and incorrect UTF8 sequences at the beginning, middle and end of a byte array. Also verify an all zeros (hidden) SSID of varying length.
This commit is contained in:
parent
ab16513cc1
commit
e67d919048
@ -70,7 +70,8 @@ noinst_PROGRAMS = tools/hwsim
|
||||
tools_hwsim_LDADD = ell/libell-internal.la
|
||||
|
||||
unit_tests = unit/test-pbkdf2-sha1 unit/test-prf-sha1 unit/test-ie \
|
||||
unit/test-crypto unit/test-mpdu unit/test-eapol
|
||||
unit/test-crypto unit/test-mpdu unit/test-eapol \
|
||||
unit/test-ssid-to-utf8
|
||||
|
||||
if MAINTAINER_MODE
|
||||
noinst_PROGRAMS += $(unit_tests)
|
||||
@ -99,6 +100,11 @@ unit_test_mpdu_LDADD = ell/libell-internal.la
|
||||
unit_test_eapol_SOURCES = unit/test-eapol.c \
|
||||
src/eapol.h src/eapol.c
|
||||
unit_test_eapol_LDADD = ell/libell-internal.la
|
||||
|
||||
unit_test_ssid_to_utf8_SOURCES = src/util.h src/util.c \
|
||||
unit/test-ssid-to-utf8.c
|
||||
unit_test_ssid_to_utf8_LDADD = ell/libell-internal.la
|
||||
|
||||
TESTS = $(unit_tests)
|
||||
|
||||
manual_pages = doc/iwmon.1
|
||||
|
87
unit/test-ssid-to-utf8.c
Normal file
87
unit/test-ssid-to-utf8.c
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
*
|
||||
* Wireless daemon for Linux
|
||||
*
|
||||
* Copyright (C) 2014 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <ell/ell.h>
|
||||
|
||||
#include "src/util.h"
|
||||
|
||||
struct ssid_test_data {
|
||||
size_t len;
|
||||
uint8_t ssid[32];
|
||||
const char *string;
|
||||
bool result;
|
||||
};
|
||||
|
||||
const struct ssid_test_data ssid_samples[] = {
|
||||
{ 0, { }, "", true },
|
||||
{ 1, { }, "", true },
|
||||
{ 32, { }, "", true },
|
||||
{ 33, { }, "", true },
|
||||
{ 33, { 'a', 'b', 'c', }, "", true },
|
||||
{ 42, { }, "", true },
|
||||
{ 3, { 'f', 'o', 'o', }, "foo", true },
|
||||
{ 3, { }, "", true },
|
||||
{ 3, { 'f', 'o', 'o', }, "bar", false },
|
||||
{ 3, { 'f', 'o', 'o', 0xff, }, "foo", true },
|
||||
{ 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "fooba", true },
|
||||
{ 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "foobar", false },
|
||||
{ 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "oobar", false },
|
||||
{ 4, { 'x', 'y', 'z', 0xff }, "xyz<EFBFBD>", true },
|
||||
{ 6, { 'x', 'y', 'z', 0xff, '1', '2' }, "xyz<EFBFBD>12", true },
|
||||
{ 7, { 0xf0, 0xf3, '3', '4', '5', '6', '7', }, "<EFBFBD><EFBFBD>34567", true },
|
||||
{ 6, { 0xc3, 0x96, '3', '4', '5', '6' }, "Ö3456", true },
|
||||
{ 6, { '1', 0xc3, 0x96, '4', '5', '6' }, "1Ö456", true },
|
||||
{ 6, { '1', '2', '3', '4', 0xc3, 0x96 }, "1234Ö", true },
|
||||
};
|
||||
|
||||
static void ssid_to_utf8(const void *data)
|
||||
{
|
||||
const struct ssid_test_data *ssid = data;
|
||||
int i = 0, samples = sizeof(ssid_samples) / sizeof(ssid_samples[0]);
|
||||
|
||||
while (i < samples) {
|
||||
const char *result = util_ssid_to_utf8(ssid[i].len,
|
||||
ssid[i].ssid);
|
||||
|
||||
assert(!memcmp(ssid[i].string, result,
|
||||
strlen(ssid[i].string)) == ssid[i].result);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
l_test_init(&argc, &argv);
|
||||
|
||||
l_test_add("/util/ssid_to_utf8/", ssid_to_utf8, ssid_samples);
|
||||
|
||||
return l_test_run();
|
||||
}
|
Loading…
Reference in New Issue
Block a user