diff --git a/ChangeLog b/ChangeLog index 710250a2b..52e02645c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-12-21 Dan Williams + + * test/libnm-util + - Add some testcases for WEP ciphers + 2005-12-17 Dan Williams * Fix bugs diff --git a/configure.in b/configure.in index 9bc31ef78..c1cc4cfc1 100644 --- a/configure.in +++ b/configure.in @@ -300,6 +300,7 @@ gnome/libnm_glib/libnm_glib.pc gnome/libnm_glib/Makefile gnome/vpn-properties/Makefile test/Makefile +test/libnm-util/Makefile initscript/Makefile initscript/RedHat/Makefile initscript/RedHat/NetworkManager diff --git a/libnm-util/cipher-wep-ascii.c b/libnm-util/cipher-wep-ascii.c index f556c0857..3a5552a30 100644 --- a/libnm-util/cipher-wep-ascii.c +++ b/libnm-util/cipher-wep-ascii.c @@ -58,12 +58,12 @@ IEEE_802_11_Cipher * cipher_wep128_ascii_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_WEP104; cipher->input_min = WEP128_ASCII_INPUT_SIZE; cipher->input_max = WEP128_ASCII_INPUT_SIZE; cipher->cipher_hash_func = cipher_wep128_ascii_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } @@ -82,12 +82,12 @@ IEEE_802_11_Cipher * cipher_wep64_ascii_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_WEP40; cipher->input_min = WEP64_ASCII_INPUT_SIZE; cipher->input_max = WEP64_ASCII_INPUT_SIZE; cipher->cipher_hash_func = cipher_wep64_ascii_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } diff --git a/libnm-util/cipher-wep-hex.c b/libnm-util/cipher-wep-hex.c index b1ba37011..c52e6b2dc 100644 --- a/libnm-util/cipher-wep-hex.c +++ b/libnm-util/cipher-wep-hex.c @@ -120,12 +120,12 @@ IEEE_802_11_Cipher * cipher_wep128_hex_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_WEP104; cipher->input_min = WEP128_HEX_INPUT_SIZE; cipher->input_max = WEP128_HEX_INPUT_SIZE; cipher->cipher_hash_func = cipher_wep128_hex_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } @@ -144,12 +144,12 @@ IEEE_802_11_Cipher * cipher_wep64_hex_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_WEP40; cipher->input_min = WEP64_HEX_INPUT_SIZE; cipher->input_max = WEP64_HEX_INPUT_SIZE; cipher->cipher_hash_func = cipher_wep64_hex_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } diff --git a/libnm-util/cipher-wep-passphrase.c b/libnm-util/cipher-wep-passphrase.c index ee7ea5fa0..3dfff2ad5 100644 --- a/libnm-util/cipher-wep-passphrase.c +++ b/libnm-util/cipher-wep-passphrase.c @@ -102,12 +102,12 @@ IEEE_802_11_Cipher * cipher_wep128_passphrase_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_WEP104; cipher->input_min = 1; /* What _is_ the min, really? */ cipher->input_max = 64; cipher->cipher_hash_func = cipher_wep128_passphrase_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } @@ -124,12 +124,12 @@ IEEE_802_11_Cipher * cipher_wep64_passphrase_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_WEP40; cipher->input_min = 1; /* What _is_ the min, really? */ cipher->input_max = 64; cipher->cipher_hash_func = cipher_wep64_passphrase_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } diff --git a/libnm-util/cipher-wpa-psk-hex.c b/libnm-util/cipher-wpa-psk-hex.c index f9e13acd6..3932effb3 100644 --- a/libnm-util/cipher-wpa-psk-hex.c +++ b/libnm-util/cipher-wpa-psk-hex.c @@ -78,12 +78,12 @@ IEEE_802_11_Cipher * cipher_wpa_psk_hex_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_TKIP; cipher->input_min = 2; cipher->input_max = WPA_PMK_LEN * 2; cipher->cipher_hash_func = cipher_wpa_psk_hex_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } diff --git a/libnm-util/cipher-wpa-psk-passphrase.c b/libnm-util/cipher-wpa-psk-passphrase.c index 441070089..f14ffb2eb 100644 --- a/libnm-util/cipher-wpa-psk-passphrase.c +++ b/libnm-util/cipher-wpa-psk-passphrase.c @@ -36,12 +36,12 @@ IEEE_802_11_Cipher * cipher_wpa_psk_passphrase_new (void) { IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher)); + cipher->refcount = 1; cipher->we_cipher = IW_AUTH_CIPHER_TKIP; cipher->input_min = 8; cipher->input_max = WPA_PMK_LEN * 2; cipher->cipher_hash_func = cipher_wpa_psk_passphrase_hash_func; cipher->cipher_input_validate_func = cipher_default_validate_func; - ieee_802_11_cipher_ref (cipher); return cipher; } diff --git a/libnm-util/cipher.c b/libnm-util/cipher.c index 2d35a5abf..b8e7f03e1 100644 --- a/libnm-util/cipher.c +++ b/libnm-util/cipher.c @@ -30,6 +30,7 @@ void ieee_802_11_cipher_ref (IEEE_802_11_Cipher *cipher) { g_return_if_fail (cipher != NULL); + g_return_if_fail (cipher->refcount > 0); cipher->refcount++; } @@ -37,6 +38,7 @@ void ieee_802_11_cipher_ref (IEEE_802_11_Cipher *cipher) void ieee_802_11_cipher_unref (IEEE_802_11_Cipher *cipher) { g_return_if_fail (cipher != NULL); + g_return_if_fail (cipher->refcount > 0); cipher->refcount--; if (cipher->refcount <= 0) @@ -46,9 +48,18 @@ void ieee_802_11_cipher_unref (IEEE_802_11_Cipher *cipher) } } +int ieee_802_11_cipher_refcount (IEEE_802_11_Cipher *cipher) +{ + g_return_val_if_fail (cipher != NULL, -1); + g_return_val_if_fail (cipher->refcount > 0, -1); + + return cipher->refcount; +} + int ieee_802_11_cipher_get_we_cipher (IEEE_802_11_Cipher *cipher) { g_return_val_if_fail (cipher != NULL, -1); + g_return_val_if_fail (cipher->refcount > 0, -1); return cipher->we_cipher; } @@ -56,6 +67,7 @@ int ieee_802_11_cipher_get_we_cipher (IEEE_802_11_Cipher *cipher) int ieee_802_11_cipher_get_input_min (IEEE_802_11_Cipher *cipher) { g_return_val_if_fail (cipher != NULL, -1); + g_return_val_if_fail (cipher->refcount > 0, -1); return cipher->input_min; } @@ -63,6 +75,7 @@ int ieee_802_11_cipher_get_input_min (IEEE_802_11_Cipher *cipher) int ieee_802_11_cipher_get_input_max (IEEE_802_11_Cipher *cipher) { g_return_val_if_fail (cipher != NULL, -1); + g_return_val_if_fail (cipher->refcount > 0, -1); return cipher->input_max; } @@ -70,6 +83,7 @@ int ieee_802_11_cipher_get_input_max (IEEE_802_11_Cipher *cipher) char *ieee_802_11_cipher_hash (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input) { g_return_val_if_fail (cipher != NULL, NULL); + g_return_val_if_fail (cipher->refcount > 0, NULL); return (*cipher->cipher_hash_func)(cipher, ssid, input); } @@ -77,6 +91,7 @@ char *ieee_802_11_cipher_hash (IEEE_802_11_Cipher *cipher, const char *ssid, con int ieee_802_11_cipher_validate (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input) { g_return_val_if_fail (cipher != NULL, -1); + g_return_val_if_fail (cipher->refcount > 0, -1); if (!cipher->cipher_input_validate_func) return cipher_default_validate_func (cipher, ssid, input); @@ -92,6 +107,7 @@ int cipher_default_validate_func (IEEE_802_11_Cipher *cipher, const char *ssid, int len; g_return_val_if_fail (cipher != NULL, -1); + g_return_val_if_fail (cipher->refcount > 0, -1); g_return_val_if_fail (input != NULL, -1); len = strlen (input); diff --git a/libnm-util/cipher.h b/libnm-util/cipher.h index b14357597..94b9f603f 100644 --- a/libnm-util/cipher.h +++ b/libnm-util/cipher.h @@ -32,6 +32,9 @@ int ieee_802_11_cipher_get_input_max (IEEE_802_11_Cipher *cipher); char * ieee_802_11_cipher_hash (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input); int ieee_802_11_cipher_validate (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input); +/* Private API members (not part of the public API) */ +int ieee_802_11_cipher_refcount (IEEE_802_11_Cipher *cipher); + /* For use by ciphers themselves */ int cipher_default_validate_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input); diff --git a/test/Makefile.am b/test/Makefile.am index d5665716d..159cb410a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS=libnm-util + INCLUDES = -I${top_srcdir} \ -I${top_srcdir}/gnome/libnm_glib \ -I${top_srcdir}/utils \ @@ -13,6 +15,8 @@ AM_CPPFLAGS = \ noinst_PROGRAMS = nm-tool nminfotest nmtestdevices libnm_glib_test +noinst_LTLIBRARIES=libtest-common.la + nm_tool_SOURCES = nm-tool.c nm_tool_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \ $(top_builddir)/utils/libnmutils.la @@ -31,3 +35,14 @@ libnm_glib_test_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) \ $(top_builddir)/utils/libnmutils.la \ ../gnome/libnm_glib/libnm_glib.la + +libtest_common_la_SOURCES= \ + test-common.c \ + test-common.h + +libtest_common_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + -DG_DISABLE_DEPRECATED + +libtest_common_la_LIBADD = $(GLIB_LIBS) + diff --git a/test/libnm-util/Makefile.am b/test/libnm-util/Makefile.am new file mode 100644 index 000000000..3851b309a --- /dev/null +++ b/test/libnm-util/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES = -I${top_srcdir} \ + -I${top_srcdir}/utils \ + -I${top_srcdir}/include \ + -I${top_srcdir}/libnm-util \ + -I${top_srcdir}/test + +noinst_PROGRAMS = test-ciphers + +test_ciphers_SOURCES = test-ciphers.c + +test_ciphers_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) \ + -DDBUS_API_SUBJECT_TO_CHANGE \ + -DBINDIR=\"$(bindir)\" \ + -DDATADIR=\"$(datadir)\" + +test_ciphers_LDADD = \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(top_builddir)/test/libtest-common.la diff --git a/test/libnm-util/test-ciphers.c b/test/libnm-util/test-ciphers.c new file mode 100644 index 000000000..06f9142e9 --- /dev/null +++ b/test/libnm-util/test-ciphers.c @@ -0,0 +1,258 @@ +/* NetworkManager -- Forget about your network + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2005 Red Hat, Inc. + */ + +#include +#include +#include +#include + +#include "cipher.h" +#include "cipher-wep-ascii.h" +#include "cipher-wep-hex.h" +#include "cipher-wep-passphrase.h" +#include "test-common.h" + +static char *progname = NULL; + +static void test_refcounts (IEEE_802_11_Cipher *cipher, const char *test) +{ + if (ieee_802_11_cipher_refcount (cipher) != 1) + test_result (progname, test, TEST_FAIL, "Cipher refcount after creation was not 1.\n"); + + ieee_802_11_cipher_ref (cipher); + if (ieee_802_11_cipher_refcount (cipher) != 2) + test_result (progname, test, TEST_FAIL, "Cipher refcount after ref was not 2.\n"); + + ieee_802_11_cipher_unref (cipher); + if (ieee_802_11_cipher_refcount (cipher) != 1) + test_result (progname, test, TEST_FAIL, "Cipher refcount after unref #1 was not 1.\n"); + + ieee_802_11_cipher_unref (cipher); + if (ieee_802_11_cipher_refcount (cipher) != -1) + test_result (progname, test, TEST_FAIL, "Cipher refcount after unref #2 was not invalid.\n"); + + test_result (progname, test, TEST_SUCCEED, NULL); +} + + +struct Inputs +{ + char * underrun; + char * overrun; + char * incorrect_input; + char * correct_input; + char correct_output[100]; +}; + +#define WEP128_ASCII_SELECTOR 0 +#define WEP64_ASCII_SELECTOR 1 +#define WEP128_HEX_SELECTOR 2 +#define WEP64_HEX_SELECTOR 3 +#define WEP128_PASSPHRASE_SELECTOR 4 +#define WEP64_PASSPHRASE_SELECTOR 5 + +struct Inputs test_input[6] = +{ + { + /* WEP128 ASCII */ + "ph34rm3", + "herecomessantaclaus", + NULL, + "1234567891234", + { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x31, 0x32, 0x33, 0x34, 0x00 } + }, + { + /* WEP64 ASCII */ + "1234", + "herecomessantaclaus", + NULL, + "12345", + { 0x31, 0x32, 0x33, 0x34, 0x35, 0x00 } + }, + { + /* WEP128 Hex */ + "3dff2f1f93a87ad", + "3235ab39b9b2e32fda8a919b9a021458", + "qwertyuiopjxccjvjpapadfjcd", + "4ec5de9938b606e9d40dff721e", + { 0x4e, 0xc5, 0xde, 0x99, 0x38, 0xb6, 0x06, 0xe9, 0xd4, 0x0d, 0xff, 0x72, 0x1e, 0x00 } + }, + { + /* WEP64 Hex */ + "3dff2f1f", + "3235ab39b9b2e", + "qwertyuiop", + "4ec5de9938", + { 0x4e, 0xc5, 0xde, 0x99, 0x38 } + }, + { + /* WEP128 Passphrse */ + "", + "3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb", + NULL, + "You don't remember me but I remember you.", + { 0x30, 0x36, 0x61, 0x39, 0x63, 0x37, 0x30, 0x37, 0x31, 0x35, 0x66, 0x65, 0x30, + 0x36, 0x31, 0x32, 0x39, 0x63, 0x36, 0x32, 0x35, 0x61, 0x32, 0x34, 0x38, 0x64 } + }, + { + /* WEP64 Passphrse */ + "", + "3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb", + NULL, + "Have you forgotten all I know?", + { 0x31, 0x38, 0x30, 0x37, 0x34, 0x66, 0x33, 0x31, 0x37, 0x38 } + } +}; + +static void test_inputs (IEEE_802_11_Cipher *cipher, const char *test, int selector) +{ +#define ESSID "foobar" + struct Inputs * input = &test_input[selector]; + char *output; + char *correct_output; + + /* Underrun */ + if ((ieee_802_11_cipher_validate (cipher, ESSID, input->underrun)) != -1) + test_result (progname, test, TEST_FAIL, "Input underrun was not rejected!\n"); + + /* Overrun */ + if (input->overrun && (ieee_802_11_cipher_validate (cipher, ESSID, input->overrun)) != -1) + test_result (progname, test, TEST_FAIL, "Input overrun was not rejected!\n"); + + /* Incorrect input */ + if (input->incorrect_input && (ieee_802_11_cipher_validate (cipher, ESSID, input->incorrect_input)) != -1) + test_result (progname, test, TEST_FAIL, "Incorrect input was not rejected!\n"); + + /* Acceptance of correct input */ + if ((ieee_802_11_cipher_validate (cipher, ESSID, input->correct_input)) != 0) + test_result (progname, test, TEST_FAIL, "Correct input was not accepted!\n"); + + /* Actually hash the correct input */ + if (!(output = ieee_802_11_cipher_hash (cipher, ESSID, input->correct_input))) + test_result (progname, test, TEST_FAIL, "Correct input was not hashed!\n"); + + /* Compare to known output */ + if (memcmp (output, input->correct_output, strlen (input->correct_output)) != 0) + test_result (progname, test, TEST_FAIL, "Hashed output did not match expected!\n"); + + test_result (progname, test, TEST_SUCCEED, NULL); +} + +static void test_wep_ascii (void) +{ + IEEE_802_11_Cipher *cipher; + + /* Test basic object creation */ + if (!(cipher = cipher_wep128_ascii_new ())) + test_result (progname, "new_wep128_ascii", TEST_FAIL, "Could not create WEP104 ASCII cipher.\n"); + test_result (progname, "new_wep128_ascii", TEST_SUCCEED, NULL); + /* Test object refcounting */ + test_refcounts (cipher, "wep128_ascii_refcounts"); + + /* Test basic object creation */ + if (!(cipher = cipher_wep64_ascii_new ())) + test_result (progname, "new_wep64_ascii", TEST_FAIL, "Could not create WEP40 ASCII cipher.\n"); + test_result (progname, "new_wep64_ascii", TEST_SUCCEED, NULL); + /* Test object refcounting */ + test_refcounts (cipher, "wep64_ascii_refcounts"); + + /* Test inputs */ + if (!(cipher = cipher_wep128_ascii_new ())) + test_result (progname, "new_wep128_ascii", TEST_FAIL, "Could not create WEP104 ASCII cipher.\n"); + test_inputs (cipher, "inputs_wep128_ascii", WEP128_ASCII_SELECTOR); + ieee_802_11_cipher_unref (cipher); + + if (!(cipher = cipher_wep64_ascii_new ())) + test_result (progname, "new_wep64_ascii", TEST_FAIL, "Could not create WEP40 ASCII cipher.\n"); + test_inputs (cipher, "inputs_wep64_ascii", WEP64_ASCII_SELECTOR); + ieee_802_11_cipher_unref (cipher); +} + +static void test_wep_hex (void) +{ + IEEE_802_11_Cipher *cipher; + + /* Test basic object creation */ + if (!(cipher = cipher_wep128_hex_new ())) + test_result (progname, "new_wep128_hex", TEST_FAIL, "Could not create WEP104 Hex cipher.\n"); + test_result (progname, "new_wep128_hex", TEST_SUCCEED, NULL); + /* Test object refcounting */ + test_refcounts (cipher, "wep128_hex_refcounts"); + + /* Test basic object creation */ + if (!(cipher = cipher_wep64_hex_new ())) + test_result (progname, "new_wep64_hex", TEST_FAIL, "Could not create WEP40 Hex cipher.\n"); + test_result (progname, "new_wep64_hex", TEST_SUCCEED, NULL); + /* Test object refcounting */ + test_refcounts (cipher, "wep64_hex_refcounts"); + + /* Test inputs */ + if (!(cipher = cipher_wep128_hex_new ())) + test_result (progname, "new_wep128_hex", TEST_FAIL, "Could not create WEP104 Hex cipher.\n"); + test_inputs (cipher, "inputs_wep128_hex", WEP128_HEX_SELECTOR); + ieee_802_11_cipher_unref (cipher); + + if (!(cipher = cipher_wep64_hex_new ())) + test_result (progname, "new_wep64_hex", TEST_FAIL, "Could not create WEP40 Hex cipher.\n"); + test_inputs (cipher, "inputs_wep64_hex", WEP64_HEX_SELECTOR); + ieee_802_11_cipher_unref (cipher); +} + +static void test_wep_passphrase (void) +{ + IEEE_802_11_Cipher *cipher; + + /* Test basic object creation */ + if (!(cipher = cipher_wep128_passphrase_new ())) + test_result (progname, "new_wep128_passphrase", TEST_FAIL, "Could not create WEP104 Passphrase cipher.\n"); + test_result (progname, "new_wep128_passphrase", TEST_SUCCEED, NULL); + /* Test object refcounting */ + test_refcounts (cipher, "wep128_passphrase_refcounts"); + + /* Test basic object creation */ + if (!(cipher = cipher_wep64_passphrase_new ())) + test_result (progname, "new_wep64_passphrase", TEST_FAIL, "Could not create WEP40 Passphrase cipher.\n"); + test_result (progname, "new_wep64_passphrase", TEST_SUCCEED, NULL); + /* Test object refcounting */ + test_refcounts (cipher, "wep64_passphrase_refcounts"); + + /* Test inputs */ + if (!(cipher = cipher_wep128_passphrase_new ())) + test_result (progname, "new_wep128_passphrase", TEST_FAIL, "Could not create WEP104 Passphrase cipher.\n"); + test_inputs (cipher, "inputs_wep128_passphrase", WEP128_PASSPHRASE_SELECTOR); + ieee_802_11_cipher_unref (cipher); + + if (!(cipher = cipher_wep64_passphrase_new ())) + test_result (progname, "new_wep64_passphrase", TEST_FAIL, "Could not create WEP40 Passphrase cipher.\n"); + test_inputs (cipher, "inputs_wep64_passphrase", WEP64_PASSPHRASE_SELECTOR); + ieee_802_11_cipher_unref (cipher); +} + +int main (int argc, char **argv) +{ + progname = argv[0]; + + test_wep_ascii (); + test_wep_hex (); + test_wep_passphrase (); + + return 0; +} diff --git a/test/test-common.c b/test/test-common.c new file mode 100644 index 000000000..5d2d99069 --- /dev/null +++ b/test/test-common.c @@ -0,0 +1,63 @@ +/* NetworkManager -- Forget about your network + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2005 Red Hat, Inc. + */ + + +#include +#include +#include + +#include "test-common.h" + + +void +test_result (const char *progname, + const char *test, + TestResult result, + const char *format, + ...) +{ + va_list args; + char * errmsg = NULL; + char * full_msg = NULL; + char * result_string = NULL; + + if (format) + { + errmsg = g_malloc0 (257); + va_start (args, format); + vsnprintf (errmsg, 256, format, args); + va_end (args); + } + + if (result == TEST_FAIL) + result_string = "FAIL"; + else + result_string = "SUCCEED"; + + full_msg = g_strdup_printf ("%s: (%s) %s %s\n", progname, test, result_string, errmsg ? errmsg : ""); + fprintf (stderr, full_msg); + g_free (full_msg); + g_free (errmsg); + + if (result == TEST_FAIL) + exit (-1); +} + diff --git a/test/test-common.h b/test/test-common.h new file mode 100644 index 000000000..643413760 --- /dev/null +++ b/test/test-common.h @@ -0,0 +1,41 @@ +/* NetworkManager -- Forget about your network + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2005 Red Hat, Inc. + */ + +#ifndef TEST_COMMON_H +#define TEST_COMMON_H + +#include +#include +#include + +typedef enum TestResult +{ + TEST_FAIL = 0, + TEST_SUCCEED +} TestResult; + +void test_result (const char *progname, + const char *test, + TestResult result, + const char *format, + ...); + +#endif /* TEST_COMMON_H */