libwmc: beginning of bits for WMC-based devices like UML290
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir)/libwmc/src
|
||||
|
||||
noinst_PROGRAMS = test-wmc
|
||||
|
||||
test_wmc_SOURCES = \
|
||||
test-wmc-crc.c \
|
||||
test-wmc-crc.h \
|
||||
test-wmc-escaping.c \
|
||||
test-wmc-escaping.h \
|
||||
test-wmc-utils.c \
|
||||
test-wmc-utils.h \
|
||||
test-wmc.c
|
||||
|
||||
test_wmc_CPPFLAGS = \
|
||||
$(MM_CFLAGS)
|
||||
|
||||
test_wmc_LDADD = \
|
||||
$(top_builddir)/libwmc/src/libwmc.la \
|
||||
$(MM_LIBS)
|
||||
|
||||
if WITH_TESTS
|
||||
|
||||
check-local: test-wmc
|
||||
$(abs_builddir)/test-wmc
|
||||
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-wmc-crc.h"
|
||||
#include "utils.h"
|
||||
|
||||
void
|
||||
test_crc16_2 (void *f, void *data)
|
||||
{
|
||||
static const char buf[] = {
|
||||
0x26, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00
|
||||
};
|
||||
guint16 crc;
|
||||
guint16 expected = 0x6D69;
|
||||
|
||||
/* CRC check */
|
||||
crc = crc16 (buf, sizeof (buf), 0);
|
||||
g_assert (crc == expected);
|
||||
}
|
||||
|
||||
void
|
||||
test_crc16_1 (void *f, void *data)
|
||||
{
|
||||
static const char buf[] = {
|
||||
0x4b, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f,
|
||||
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
guint16 crc;
|
||||
guint16 expected = 0x097A;
|
||||
|
||||
/* CRC check */
|
||||
crc = crc16 (buf, sizeof (buf), 0);
|
||||
g_assert (crc == expected);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TEST_WMC_CRC_H
|
||||
#define TEST_WMC_CRC_H
|
||||
|
||||
void test_crc16_2 (void *f, void *data);
|
||||
void test_crc16_1 (void *f, void *data);
|
||||
|
||||
#endif /* TEST_WMC_CRC_H */
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-wmc-escaping.h"
|
||||
#include "utils.h"
|
||||
|
||||
static const char data1[] = {
|
||||
0x70, 0x68, 0x6f, 0x6e, 0x65, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65,
|
||||
0x0a, 0x6e, 0x6f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x74, 0x6f, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x0a, 0x70, 0x68, 0x6f,
|
||||
0x6e, 0x7e, 0x7e, 0x7e, 0x7d, 0x7d, 0x7e, 0x7d, 0x7e, 0x7d, 0x7e, 0x6e,
|
||||
0x6b, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x0a, 0x6f, 0x70,
|
||||
0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x6c,
|
||||
0x6c, 0x6f, 0x77, 0x65, 0x64, 0x0a, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x6e, 0x6f, 0x74, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72,
|
||||
0x74, 0x65, 0x64, 0x0a, 0x70, 0x68, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e,
|
||||
0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x70, 0x68, 0x66,
|
||||
0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72,
|
||||
0x65, 0x64, 0x0a, 0x70, 0x68, 0x66, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b,
|
||||
0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d,
|
||||
0x6e, 0x6f, 0x74, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x65, 0x64, 0x0a,
|
||||
0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72,
|
||||
0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b, 0x72, 0x65, 0x71,
|
||||
0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x66, 0x61, 0x69,
|
||||
0x6c, 0x75, 0x72, 0x65, 0x0a, 0x73, 0x69, 0x6d, 0x62, 0x75, 0x73, 0x79,
|
||||
0x0a, 0x73, 0x69, 0x6d, 0x77, 0x72, 0x6f, 0x6e, 0x67, 0x0a, 0x69, 0x6e,
|
||||
0x63, 0x6f, 0x72, 0x72, 0x65, 0x63, 0x74, 0x70, 0x61, 0x73, 0x73, 0x77,
|
||||
0x6f, 0x72, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x32, 0x72,
|
||||
0x65, 0x71, 0x75, 0x69
|
||||
};
|
||||
|
||||
static const char expected1[] = {
|
||||
0x70, 0x68, 0x6f, 0x6e, 0x65, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65,
|
||||
0x0a, 0x6e, 0x6f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x74, 0x6f, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x0a, 0x70, 0x68, 0x6f,
|
||||
0x6e, 0x7d, 0x5e, 0x7d, 0x5e, 0x7d, 0x5e, 0x7d, 0x5d, 0x7d, 0x5d, 0x7d,
|
||||
0x5e, 0x7d, 0x5d, 0x7d, 0x5e, 0x7d, 0x5d, 0x7d, 0x5e, 0x6e, 0x6b, 0x72,
|
||||
0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x0a, 0x6f, 0x70, 0x65, 0x72,
|
||||
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x6c, 0x6c, 0x6f,
|
||||
0x77, 0x65, 0x64, 0x0a, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x6e, 0x6f, 0x74, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65,
|
||||
0x64, 0x0a, 0x70, 0x68, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65,
|
||||
0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x70, 0x68, 0x66, 0x73, 0x69,
|
||||
0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64,
|
||||
0x0a, 0x70, 0x68, 0x66, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b, 0x72, 0x65,
|
||||
0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x6e, 0x6f,
|
||||
0x74, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x65, 0x64, 0x0a, 0x73, 0x69,
|
||||
0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64,
|
||||
0x0a, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b, 0x72, 0x65, 0x71, 0x75, 0x69,
|
||||
0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x66, 0x61, 0x69, 0x6c, 0x75,
|
||||
0x72, 0x65, 0x0a, 0x73, 0x69, 0x6d, 0x62, 0x75, 0x73, 0x79, 0x0a, 0x73,
|
||||
0x69, 0x6d, 0x77, 0x72, 0x6f, 0x6e, 0x67, 0x0a, 0x69, 0x6e, 0x63, 0x6f,
|
||||
0x72, 0x72, 0x65, 0x63, 0x74, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72,
|
||||
0x64, 0x0a, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x32, 0x72, 0x65, 0x71,
|
||||
0x75, 0x69
|
||||
};
|
||||
|
||||
void
|
||||
test_escape1 (void *f, void *data)
|
||||
{
|
||||
char escaped[1024];
|
||||
gsize len;
|
||||
|
||||
/* Ensure that escaping in general works */
|
||||
len = hdlc_escape (data1, sizeof (data1), FALSE, escaped, sizeof (escaped));
|
||||
g_assert (len == 266);
|
||||
g_assert (len == sizeof (expected1));
|
||||
g_assert (memcmp (escaped, expected1, len) == 0);
|
||||
}
|
||||
|
||||
static const char data2[] = {
|
||||
0x4b, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f,
|
||||
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
void
|
||||
test_escape2 (void *f, void *data)
|
||||
{
|
||||
char escaped[1024];
|
||||
gsize len;
|
||||
|
||||
/* Ensure that escaping data that doesn't need escaping works */
|
||||
len = hdlc_escape (data2, sizeof (data2), FALSE, escaped, sizeof (escaped));
|
||||
g_assert (len == sizeof (data2));
|
||||
g_assert (memcmp (escaped, data2, len) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
test_escape_unescape (void *f, void *data)
|
||||
{
|
||||
char escaped[512];
|
||||
char unescaped[512];
|
||||
gsize len, unlen;
|
||||
gboolean escaping = FALSE;
|
||||
|
||||
/* Ensure that escaping data that needs escaping, and then unescaping it,
|
||||
* produces the exact same data as was originally escaped.
|
||||
*/
|
||||
len = hdlc_escape (data1, sizeof (data1), FALSE, escaped, sizeof (escaped));
|
||||
unlen = hdlc_unescape (escaped, len, unescaped, sizeof (unescaped), &escaping);
|
||||
|
||||
g_assert (unlen == sizeof (data1));
|
||||
g_assert (memcmp (unescaped, data1, unlen) == 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TEST_WMC_ESCAPING_H
|
||||
#define TEST_WMC_ESCAPING_H
|
||||
|
||||
void test_escape1 (void *f, void *data);
|
||||
void test_escape2 (void *f, void *data);
|
||||
void test_escape_unescape (void *f, void *data);
|
||||
|
||||
#endif /* TEST_WMC_ESCAPING_H */
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-wmc-utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
static const char decap_inbuf[] = {
|
||||
0x40, 0x03, 0x00, 0x01, 0x00, 0x19, 0xf0, 0x00, 0x16, 0x00, 0x21, 0x00,
|
||||
0x1c, 0x00, 0xd8, 0x00, 0x3f, 0x00, 0x56, 0x01, 0x3f, 0x00, 0x15, 0x00,
|
||||
0x1a, 0x00, 0x11, 0x01, 0x3f, 0x00, 0x92, 0x01, 0x3f, 0x00, 0x39, 0x00,
|
||||
0x3f, 0x00, 0x95, 0x01, 0x3f, 0x00, 0x12, 0x00, 0x3f, 0x00, 0x23, 0x01,
|
||||
0x3f, 0x00, 0x66, 0x00, 0x3f, 0x00, 0x0b, 0x01, 0x3f, 0x00, 0xae, 0x00,
|
||||
0x3f, 0x00, 0x02, 0x01, 0x3f, 0x00, 0xa8, 0x00, 0x3f, 0x00, 0x50, 0x01,
|
||||
0x3f, 0x00, 0xf8, 0x01, 0x3f, 0x00, 0x57, 0x00, 0x3f, 0x00, 0x7d, 0x5e,
|
||||
0x00, 0x3f, 0x00, 0x93, 0x00, 0x3f, 0x00, 0xbd, 0x00, 0x3f, 0x00, 0x77,
|
||||
0x01, 0x3f, 0x00, 0xb7, 0x00, 0x3f, 0x00, 0xab, 0x00, 0x3f, 0x00, 0x33,
|
||||
0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
|
||||
0x13, 0x50, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x00, 0xaa, 0x19, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0xc4, 0x7d, 0x5e,
|
||||
0x7d, 0x5e, 0x7d, 0x5d, 0x5d, 0x04, 0x58, 0x1b, 0x5b, 0x1b, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x65, 0x69, 0x7e
|
||||
};
|
||||
|
||||
void
|
||||
test_utils_decapsulate_buffer (void *f, void *data)
|
||||
{
|
||||
gboolean success;
|
||||
char outbuf[512];
|
||||
gsize decap_len = 0;
|
||||
gsize used = 0;
|
||||
gboolean more = FALSE;
|
||||
|
||||
success = hdlc_decapsulate_buffer (decap_inbuf, sizeof (decap_inbuf),
|
||||
outbuf, sizeof (outbuf),
|
||||
&decap_len, &used, &more);
|
||||
g_assert (success);
|
||||
g_assert (decap_len == 214);
|
||||
g_assert (used == 221);
|
||||
g_assert (more == FALSE);
|
||||
}
|
||||
|
||||
|
||||
static const char encap_outbuf[] = {
|
||||
0x4b, 0x05, 0x08, 0x00, 0x01, 0xdd, 0x7e
|
||||
};
|
||||
|
||||
void
|
||||
test_utils_encapsulate_buffer (void *f, void *data)
|
||||
{
|
||||
char cmdbuf[10];
|
||||
char outbuf[512];
|
||||
gsize encap_len = 0;
|
||||
|
||||
cmdbuf[0] = 0x4B; /* DIAG_CMD_SUBSYS */
|
||||
cmdbuf[1] = 0x05; /* DIAG_SUBSYS_HDR */
|
||||
cmdbuf[2] = 0x08; /* first byte of DIAG_SUBSYS_HDR_STATE_INFO in LE */
|
||||
cmdbuf[3] = 0x00; /* second byte of DIAG_SUBSYS_HDR_STATE_INFO in LE */
|
||||
|
||||
encap_len = hdlc_encapsulate_buffer (cmdbuf, 4, sizeof (cmdbuf),
|
||||
0, TRUE, FALSE,
|
||||
&outbuf[0], sizeof (outbuf));
|
||||
g_assert (encap_len == sizeof (encap_outbuf));
|
||||
g_assert (memcmp (outbuf, encap_outbuf, encap_len) == 0);
|
||||
}
|
||||
|
||||
static const char cns_inbuf[] = {
|
||||
0x00, 0x0a, 0x6b, 0x74, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x7e
|
||||
};
|
||||
|
||||
void
|
||||
test_utils_decapsulate_sierra_cns (void *f, void *data)
|
||||
{
|
||||
gboolean success;
|
||||
char outbuf[512];
|
||||
gsize decap_len = 0;
|
||||
gsize used = 0;
|
||||
gboolean more = FALSE;
|
||||
|
||||
success = hdlc_decapsulate_buffer (cns_inbuf, sizeof (cns_inbuf),
|
||||
outbuf, sizeof (outbuf),
|
||||
&decap_len, &used, &more);
|
||||
g_assert (success == FALSE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TEST_WMC_UTILS_H
|
||||
#define TEST_WMC_UTILS_H
|
||||
|
||||
void test_utils_decapsulate_buffer (void *f, void *data);
|
||||
|
||||
void test_utils_encapsulate_buffer (void *f, void *data);
|
||||
|
||||
void test_utils_decapsulate_sierra_cns (void *f, void *data);
|
||||
|
||||
#endif /* TEST_WMC_UTILS_H */
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-wmc-crc.h"
|
||||
#include "test-wmc-escaping.h"
|
||||
#include "test-wmc-utils.h"
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,25,12)
|
||||
typedef GTestFixtureFunc TCFunc;
|
||||
#else
|
||||
typedef void (*TCFunc)(void);
|
||||
#endif
|
||||
|
||||
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
GTestSuite *suite;
|
||||
gint result;
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
suite = g_test_get_root ();
|
||||
g_test_suite_add (suite, TESTCASE (test_crc16_1, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_crc16_2, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_escape1, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_escape2, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_escape_unescape, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_buffer, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_utils_encapsulate_buffer, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_sierra_cns, NULL));
|
||||
|
||||
result = g_test_run ();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user