gnome-keyring r1178 - in trunk: . gp11/tests po tests
- From: nnielsen svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-keyring r1178 - in trunk: . gp11/tests po tests
- Date: Mon, 14 Jul 2008 23:32:02 +0000 (UTC)
Author: nnielsen
Date: Mon Jul 14 23:32:02 2008
New Revision: 1178
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1178&view=rev
Log:
* gp11/tests/gp11-test.h:
* gp11/tests/gp11-test-module.c:
* gp11/tests/Makefile.am:
* gp11/tests/unit-test-gp11-attributes.c:
* gp11/tests/unit-test-gp11-module.c:
* gp11/tests/unit-test-gp11-object.c:
* gp11/tests/unit-test-gp11-session.c:
* gp11/tests/unit-test-gp11-slot.c:
* tests/gtest.make: (moved from check.make)
* tests/gtest-helpers.c: (moved from check-helpers.c)
* tests/gtest-helpers.h: (moved from check-helpers.h)
* tests/Makefile.am:
* tests/prep-gtest.sh: (moved from prep-check.sh)
* configure.in: Move to glib based testing for new stuff
Added:
trunk/tests/gtest-helpers.c
- copied, changed from r1175, /trunk/tests/check-helpers.c
trunk/tests/gtest-helpers.h
- copied, changed from r1175, /trunk/tests/check-helpers.h
trunk/tests/gtest.make
- copied, changed from r1175, /trunk/tests/check.make
trunk/tests/prep-gtest.sh
- copied, changed from r1175, /trunk/tests/prep-check.sh
Removed:
trunk/tests/check-helpers.c
trunk/tests/check-helpers.h
trunk/tests/check.make
trunk/tests/prep-check.sh
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/gp11/tests/Makefile.am
trunk/gp11/tests/gp11-test-module.c
trunk/gp11/tests/gp11-test.h
trunk/gp11/tests/unit-test-gp11-attributes.c
trunk/gp11/tests/unit-test-gp11-module.c
trunk/gp11/tests/unit-test-gp11-object.c
trunk/gp11/tests/unit-test-gp11-session.c
trunk/gp11/tests/unit-test-gp11-slot.c
trunk/po/ChangeLog
trunk/tests/Makefile.am
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Mon Jul 14 23:32:02 2008
@@ -41,7 +41,7 @@
DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc"
AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.8.0)
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16.0)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
@@ -455,17 +455,9 @@
[Build test tools and unit tests]))
if test "$enable_tests" == "yes"; then
- PKG_CHECK_MODULES(CHECK, check >= 0.9, [have_check=yes], [have_check=no])
- if test "$have_check" == "yes"; then
- echo "building tests and unit tests"
- AC_DEFINE_UNQUOTED(WITH_TESTS, 1, [Build with unit test support])
- tests_status="yes"
- enable_tests="yes"
- else
- echo "The 'check' libraries are missing, cannot build tests"
- tests_status="missing"
- enable_tests="no"
- fi
+ echo "building tests and unit tests"
+ AC_DEFINE_UNQUOTED(WITH_TESTS, 1, [Build with unit test support])
+ tests_status="yes"
else
echo "not building tests and unit tests"
tests_status="no"
Modified: trunk/gp11/tests/Makefile.am
==============================================================================
--- trunk/gp11/tests/Makefile.am (original)
+++ trunk/gp11/tests/Makefile.am Mon Jul 14 23:32:02 2008
@@ -5,9 +5,8 @@
unit-test-gp11-session.c \
unit-test-gp11-slot.c
-
UNIT_FLAGS = \
- -I.. \
+ -I$(top_srcdir)/gp11/ \
-DEXTERNAL_TEST
UNIT_PROMPT =
@@ -17,7 +16,10 @@
$(top_builddir)/gp11/libgp11.la \
libgp11-test-module.la
-include $(top_srcdir)/tests/check.make
+EXTRA_DIST = \
+ gp11-test.h
+
+include $(top_srcdir)/tests/gtest.make
# ------------------------------------------------------------------------
@@ -27,7 +29,7 @@
-avoid-version
libgp11_test_module_la_CFLAGS = \
- -I. -I../ \
+ -I$(top_srcdir)/gp11 \
-I$(top_srcdir) \
$(GLIB_CFLAGS)
Modified: trunk/gp11/tests/gp11-test-module.c
==============================================================================
--- trunk/gp11/tests/gp11-test-module.c (original)
+++ trunk/gp11/tests/gp11-test-module.c Mon Jul 14 23:32:02 2008
@@ -5,7 +5,6 @@
#include <glib.h>
-#include <check.h>
#include <string.h>
static gboolean initialized = FALSE;
@@ -53,40 +52,40 @@
void *mutex;
CK_RV rv;
- fail_unless (initialized == FALSE, "Initialized same module twice, maybe module was not finalized, outstanding refs?");
- fail_unless (pInitArgs != NULL, "Missing arguments");
+ g_assert (initialized == FALSE && "Initialized same module twice, maybe module was not finalized, outstanding refs?");
+ g_assert (pInitArgs != NULL && "Missing arguments");
args = (CK_C_INITIALIZE_ARGS_PTR)pInitArgs;
- fail_unless (args->CreateMutex != NULL, "Missing CreateMutex");
- fail_unless (args->DestroyMutex != NULL, "Missing DestroyMutex");
- fail_unless (args->LockMutex != NULL, "Missing LockMutex");
- fail_unless (args->UnlockMutex != NULL, "Missing UnlockMutex");
-
- fail_unless ((args->CreateMutex) (NULL) == CKR_ARGUMENTS_BAD, "CreateMutex succeeded wrong");
- fail_unless ((args->DestroyMutex) (NULL) == CKR_MUTEX_BAD, "DestroyMutex succeeded wrong");
- fail_unless ((args->LockMutex) (NULL) == CKR_MUTEX_BAD, "LockMutex succeeded wrong");
- fail_unless ((args->UnlockMutex) (NULL) == CKR_MUTEX_BAD, "UnlockMutex succeeded wrong");
+ g_assert (args->CreateMutex != NULL && "Missing CreateMutex");
+ g_assert (args->DestroyMutex != NULL && "Missing DestroyMutex");
+ g_assert (args->LockMutex != NULL && "Missing LockMutex");
+ g_assert (args->UnlockMutex != NULL && "Missing UnlockMutex");
+
+ g_assert ((args->CreateMutex) (NULL) == CKR_ARGUMENTS_BAD && "CreateMutex succeeded wrong");
+ g_assert ((args->DestroyMutex) (NULL) == CKR_MUTEX_BAD && "DestroyMutex succeeded wrong");
+ g_assert ((args->LockMutex) (NULL) == CKR_MUTEX_BAD && "LockMutex succeeded wrong");
+ g_assert ((args->UnlockMutex) (NULL) == CKR_MUTEX_BAD && "UnlockMutex succeeded wrong");
/* Try to create an actual mutex */
rv = (args->CreateMutex) (&mutex);
- fail_unless (rv == CKR_OK, "CreateMutex failed");
- fail_unless (mutex != NULL, "CreateMutex created null mutex");
+ g_assert (rv == CKR_OK && "CreateMutex g_assert_not_reacheded");
+ g_assert (mutex != NULL && "CreateMutex created null mutex");
/* Try and lock the mutex */
rv = (args->LockMutex) (mutex);
- fail_unless (rv == CKR_OK, "LockMutex failed");
+ g_assert (rv == CKR_OK && "LockMutex g_assert_not_reacheded");
/* Try and unlock the mutex */
rv = (args->UnlockMutex) (mutex);
- fail_unless (rv == CKR_OK, "UnlockMutex failed");
+ g_assert (rv == CKR_OK && "UnlockMutex g_assert_not_reacheded");
/* Try and destroy the mutex */
rv = (args->DestroyMutex) (mutex);
- fail_unless (rv == CKR_OK, "DestroyMutex failed");
+ g_assert (rv == CKR_OK && "DestroyMutex g_assert_not_reacheded");
/* Flags should allow OS locking and os threads */
- fail_unless ((args->flags & CKF_OS_LOCKING_OK) == CKF_OS_LOCKING_OK, "Invalid CKF_OS_LOCKING_OK flag");
- fail_unless ((args->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS) == 0, "Invalid CKF_LIBRARY_CANT_CREATE_OS_THREADS flag");
+ g_assert ((args->flags & CKF_OS_LOCKING_OK) == CKF_OS_LOCKING_OK && "Invalid CKF_OS_LOCKING_OK flag");
+ g_assert ((args->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS) == 0 && "Invalid CKF_LIBRARY_CANT_CREATE_OS_THREADS flag");
the_pin = g_strdup ("booo");
the_sessions = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, free_session);
@@ -107,8 +106,8 @@
{
- fail_unless (pReserved == NULL, "Invalid reserved pointer");
- fail_unless (initialized == TRUE, "Finalize without being initialized");
+ g_assert (pReserved == NULL && "Invalid reserved pointer");
+ g_assert (initialized == TRUE && "Finalize without being initialized");
initialized = FALSE;
g_hash_table_destroy (the_objects);
@@ -132,9 +131,7 @@
static CK_RV
test_C_GetInfo (CK_INFO_PTR pInfo)
{
-
-
- fail_unless (pInfo != NULL, "Invalid pointer to GetInfo");
+ g_assert (pInfo != NULL && "Invalid pointer to GetInfo");
memcpy (pInfo, &TEST_INFO, sizeof (*pInfo));
return CKR_OK;
}
@@ -142,9 +139,7 @@
static CK_RV
test_C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
{
-
-
- fail_unless (list != NULL, "Invalid pointer passed to GetFunctionList");
+ g_assert (list != NULL && "Invalid pointer passed to GetFunctionList");
return C_GetFunctionList (list);
}
@@ -162,9 +157,7 @@
{
CK_ULONG count;
-
-
- fail_unless (pulCount != NULL, "Invalid pulCount");
+ g_assert (pulCount != NULL && "Invalid pulCount");
count = tokenPresent ? 1 : 2;
@@ -175,7 +168,7 @@
}
if (*pulCount < count) {
- fail_unless (*pulCount, "Passed in a bad count");
+ g_assert (*pulCount && "Passed in a bad count");
return CKR_BUFFER_TOO_SMALL;
}
@@ -208,7 +201,7 @@
{
- fail_unless (pInfo != NULL, "Invalid pInfo");
+ g_assert (pInfo != NULL && "Invalid pInfo");
if (slotID == TEST_SLOT_ONE) {
memcpy (pInfo, &TEST_INFO_ONE, sizeof (*pInfo));
@@ -217,7 +210,7 @@
memcpy (pInfo, &TEST_INFO_TWO, sizeof (*pInfo));
return CKR_OK;
} else {
- fail ("Invalid slot id");
+ g_assert_not_reached (); /* "Invalid slot id" */
return CKR_SLOT_ID_INVALID;
}
}
@@ -248,7 +241,7 @@
{
- fail_unless (pInfo != NULL, "Invalid pInfo");
+ g_assert (pInfo != NULL && "Invalid pInfo");
if (slotID == TEST_SLOT_ONE) {
memcpy (pInfo, &TEST_TOKEN_ONE, sizeof (*pInfo));
@@ -256,7 +249,7 @@
} else if (slotID == TEST_SLOT_TWO) {
return CKR_TOKEN_NOT_PRESENT;
} else {
- fail ("Invalid slot id");
+ g_assert_not_reached (); /* "Invalid slot id" */
return CKR_SLOT_ID_INVALID;
}
}
@@ -273,8 +266,8 @@
{
- fail_unless (slotID == TEST_SLOT_ONE, "Invalid slotID");
- fail_unless (pulCount != NULL, "Invalid pulCount");
+ g_assert (slotID == TEST_SLOT_ONE && "Invalid slotID");
+ g_assert (pulCount != NULL && "Invalid pulCount");
/* Application only wants to know the number of slots. */
if (pMechanismList == NULL) {
@@ -283,7 +276,7 @@
}
if (*pulCount != 2) {
- fail_unless (*pulCount, "Passed in a bad count");
+ g_assert (*pulCount && "Passed in a bad count");
return CKR_BUFFER_TOO_SMALL;
}
@@ -306,8 +299,8 @@
{
- fail_unless (slotID == TEST_SLOT_ONE, "Invalid slotID");
- fail_unless (pInfo != NULL, "Invalid pInfo");
+ g_assert (slotID == TEST_SLOT_ONE && "Invalid slotID");
+ g_assert (pInfo != NULL && "Invalid pInfo");
if (type == CKM_RSA_PKCS) {
memcpy (pInfo, &TEST_MECH_RSA, sizeof (*pInfo));
@@ -316,7 +309,7 @@
memcpy (pInfo, &TEST_MECH_DSA, sizeof (*pInfo));
return CKR_OK;
} else {
- fail ("Invalid type");
+ g_assert_not_reached (); /* "Invalid type" */
return CKR_MECHANISM_INVALID;
}
}
@@ -325,12 +318,12 @@
test_C_InitToken (CK_SLOT_ID slotID, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen,
CK_UTF8CHAR_PTR pLabel)
{
- fail_unless (slotID == TEST_SLOT_ONE, "Invalid slotID");
- fail_unless (pPin != NULL, "Invalid pPin");
- fail_unless (strlen ("TEST PIN"), "Invalid ulPinLen");
- fail_unless (strncmp ((gchar*)pPin, "TEST PIN", ulPinLen) == 0, "Invalid pPin string");
- fail_unless (pLabel != NULL, "Invalid pLabel");
- fail_unless (strcmp ((gchar*)pPin, "TEST LABEL") == 0, "Invalid pLabel string");
+ g_assert (slotID == TEST_SLOT_ONE && "Invalid slotID");
+ g_assert (pPin != NULL && "Invalid pPin");
+ g_assert (strlen ("TEST PIN") && "Invalid ulPinLen");
+ g_assert (strncmp ((gchar*)pPin, "TEST PIN", ulPinLen) == 0 && "Invalid pPin string");
+ g_assert (pLabel != NULL && "Invalid pLabel");
+ g_assert (strcmp ((gchar*)pPin, "TEST LABEL") == 0 && "Invalid pLabel string");
g_free (the_pin);
the_pin = g_strndup ((gchar*)pPin, ulPinLen);
@@ -340,7 +333,7 @@
static CK_RV
test_C_WaitForSlotEvent (CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, CK_VOID_PTR pReserved)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -366,11 +359,11 @@
{
Session *sess;
- fail_unless (slotID == TEST_SLOT_ONE, "Invalid slotID");
- fail_unless (pApplication == NULL, "pApplication should be null");
- fail_unless (Notify == NULL, "Notify should be null");
- fail_unless (phSession != NULL, "Invalid phSession");
- fail_unless ((flags & CKF_SERIAL_SESSION) == CKF_SERIAL_SESSION);
+ g_assert (slotID == TEST_SLOT_ONE && "Invalid slotID");
+ g_assert (pApplication == NULL && "pApplication should be null");
+ g_assert (Notify == NULL && "Notify should be null");
+ g_assert (phSession != NULL && "Invalid phSession");
+ g_assert ((flags & CKF_SERIAL_SESSION) == CKF_SERIAL_SESSION);
sess = g_new0 (Session, 1);
sess->handle = ++unique_identifier;
@@ -390,10 +383,8 @@
{
Session *session;
-
-
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_unless (session != NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -404,9 +395,7 @@
static CK_RV
test_C_CloseAllSessions (CK_SLOT_ID slotID)
{
- fail_unless (slotID == TEST_SLOT_ONE, "Invalid slotID");
-
-
+ g_assert (slotID == TEST_SLOT_ONE && "Invalid slotID");
g_hash_table_remove_all (the_sessions);
return CKR_OK;
@@ -415,14 +404,14 @@
static CK_RV
test_C_GetFunctionStatus (CK_SESSION_HANDLE hSession)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_PARALLEL;
}
static CK_RV
test_C_CancelFunction (CK_SESSION_HANDLE hSession)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_PARALLEL;
}
@@ -431,10 +420,10 @@
{
Session *session;
- fail_unless (pInfo != NULL, "Invalid pInfo");
+ g_assert (pInfo != NULL && "Invalid pInfo");
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_unless (session != NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -446,7 +435,7 @@
test_C_InitPIN (CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pPin,
CK_ULONG ulPinLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -454,7 +443,7 @@
test_C_SetPIN (CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin,
CK_ULONG ulOldLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -462,7 +451,7 @@
test_C_GetOperationState (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pOperationState,
CK_ULONG_PTR pulOperationStateLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -471,7 +460,7 @@
CK_ULONG ulOperationStateLen, CK_OBJECT_HANDLE hEncryptionKey,
CK_OBJECT_HANDLE hAuthenticationKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -482,14 +471,14 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
- fail_unless (pPinLen == strlen (the_pin), "Wrong PIN length");
- fail_unless (strncmp ((gchar*)pPin, the_pin, pPinLen) == 0, "Wrong PIN");
- fail_unless (userType == CKU_SO || userType == CKU_USER || userType == CKU_CONTEXT_SPECIFIC, "Bad user type");
- fail_unless (session->logged_in == FALSE, "Already logged in");
+ g_assert (pPinLen == strlen (the_pin) && "Wrong PIN length");
+ g_assert (strncmp ((gchar*)pPin, the_pin, pPinLen) == 0 && "Wrong PIN");
+ g_assert ((userType == CKU_SO || userType == CKU_USER || userType == CKU_CONTEXT_SPECIFIC) && "Bad user type");
+ g_assert (session->logged_in == FALSE && "Already logged in");
session->logged_in = TRUE;
session->user_type = userType;
@@ -502,11 +491,11 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_unless (session != NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
- fail_unless (session->logged_in, "Not logged in");
+ g_assert (session->logged_in && "Not logged in");
session->logged_in = FALSE;
session->user_type = 0;
return CKR_OK;
@@ -521,10 +510,10 @@
gboolean token;
CK_ULONG i;
- fail_if (phObject == NULL);
+ g_assert (phObject != NULL);
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -546,7 +535,7 @@
CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
CK_OBJECT_HANDLE_PTR phNewObject)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -557,13 +546,13 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
if (!g_hash_table_remove (the_objects, GUINT_TO_POINTER (hObject)) &&
!g_hash_table_remove (session->objects, GUINT_TO_POINTER (hObject))) {
- fail ("no such object found");
+ g_assert_not_reached (); /* "no such object found" */
return CKR_OBJECT_HANDLE_INVALID;
}
@@ -574,7 +563,7 @@
test_C_GetObjectSize (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
CK_ULONG_PTR pulSize)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -590,7 +579,7 @@
CK_ULONG i;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -598,7 +587,7 @@
if (!attrs)
attrs = g_hash_table_lookup (session->objects, GUINT_TO_POINTER (hObject));
if (!attrs) {
- fail ("invalid object handle passed");
+ g_assert_not_reached (); /* "invalid object handle passed" */
return CKR_OBJECT_HANDLE_INVALID;
}
@@ -639,7 +628,7 @@
CK_ULONG i;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -647,7 +636,7 @@
if (!attrs)
attrs = g_hash_table_lookup (session->objects, GUINT_TO_POINTER (hObject));
if (!attrs) {
- fail ("invalid object handle passed");
+ g_assert_not_reached (); /* "invalid object handle passed" */
return CKR_OBJECT_HANDLE_INVALID;
}
@@ -679,12 +668,12 @@
CK_ULONG i;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
if (session->operation != 0) {
- fail ("invalid call to FindObjectsInit");
+ g_assert_not_reached (); /* "invalid call to FindObjectsInit" */
return CKR_OPERATION_ACTIVE;
}
@@ -747,17 +736,17 @@
{
Session *session;
- fail_if (phObject == NULL);
- fail_if (pulObjectCount == NULL);
- fail_if (ulMaxObjectCount == 0);
+ g_assert (phObject != NULL);
+ g_assert (pulObjectCount != NULL);
+ g_assert (ulMaxObjectCount != 0);
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
if (session->operation != OP_FIND) {
- fail ("invalid call to FindObjects");
+ g_assert_not_reached (); /* "invalid call to FindObjects" */
return CKR_OPERATION_NOT_INITIALIZED;
}
@@ -780,12 +769,12 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
if (session->operation != OP_FIND) {
- fail ("invalid call to FindObjectsFinal");
+ g_assert_not_reached (); /* "invalid call to FindObjectsFinal" */
return CKR_OPERATION_NOT_INITIALIZED;
}
@@ -804,7 +793,7 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -816,7 +805,7 @@
PROCESS_CALL ((hSession, pMechanism, hKey))
DONE_CALL
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -829,7 +818,7 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -841,7 +830,7 @@
OUT_BYTE_ARRAY (pEncryptedData, pulEncryptedDataLen)
DONE_CALL
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -851,7 +840,7 @@
CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
CK_ULONG_PTR pulEncryptedPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -859,7 +848,7 @@
test_C_EncryptFinal (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pLastEncryptedPart,
CK_ULONG_PTR pulLastEncryptedPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -871,7 +860,7 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -883,7 +872,7 @@
PROCESS_CALL ((hSession, pMechanism, hKey))
DONE_CALL
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -896,7 +885,7 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -908,7 +897,7 @@
OUT_BYTE_ARRAY (pData, pulDataLen)
DONE_CALL
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -917,7 +906,7 @@
test_C_DecryptUpdate (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart,
CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -925,14 +914,14 @@
test_C_DecryptFinal (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pLastPart,
CK_ULONG_PTR pulLastPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
static CK_RV
test_C_DigestInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -940,21 +929,21 @@
test_C_Digest (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
static CK_RV
test_C_DigestUpdate (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
static CK_RV
test_C_DigestKey (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -962,7 +951,7 @@
test_C_DigestFinal (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest,
CK_ULONG_PTR pulDigestLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -974,13 +963,13 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -993,13 +982,13 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -1007,7 +996,7 @@
static CK_RV
test_C_SignUpdate (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1015,7 +1004,7 @@
test_C_SignFinal (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
CK_ULONG_PTR pulSignatureLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1023,7 +1012,7 @@
test_C_SignRecoverInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
CK_OBJECT_HANDLE hKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1031,7 +1020,7 @@
test_C_SignRecover (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1043,7 +1032,7 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -1055,7 +1044,7 @@
PROCESS_CALL ((hSession, pMechanism, hKey))
DONE_CALL
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -1068,7 +1057,7 @@
Session *session;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- fail_if (session == NULL, "No such session found");
+ g_assert (session != NULL && "No such session found");
if (!session)
return CKR_SESSION_HANDLE_INVALID;
@@ -1080,7 +1069,7 @@
PROCESS_CALL ((hSession, pData, ulDataLen, pSignature, pulSignatureLen))
DONE_CALL
#else
- fail ("Not yet implemented");
+ g_assert_not_reached (); /* "Not yet implemented" */
return CKR_FUNCTION_NOT_SUPPORTED;
#endif
}
@@ -1088,7 +1077,7 @@
static CK_RV
test_C_VerifyUpdate (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1096,7 +1085,7 @@
test_C_VerifyFinal (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
CK_ULONG pulSignatureLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1104,7 +1093,7 @@
test_C_VerifyRecoverInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
CK_OBJECT_HANDLE hKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1112,7 +1101,7 @@
test_C_VerifyRecover (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
CK_ULONG pulSignatureLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1121,7 +1110,7 @@
CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
CK_ULONG_PTR ulEncryptedPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1130,7 +1119,7 @@
CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart,
CK_ULONG_PTR pulPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1139,7 +1128,7 @@
CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
CK_ULONG_PTR ulEncryptedPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1148,7 +1137,7 @@
CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart,
CK_ULONG_PTR pulPartLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1157,7 +1146,7 @@
CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
CK_OBJECT_HANDLE_PTR phKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1167,7 +1156,7 @@
CK_ATTRIBUTE_PTR pPrivateKeyTemplate, CK_ULONG ulPrivateKeyAttributeCount,
CK_OBJECT_HANDLE_PTR phPublicKey, CK_OBJECT_HANDLE_PTR phPrivateKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1176,7 +1165,7 @@
CK_OBJECT_HANDLE hWrappingKey, CK_OBJECT_HANDLE hKey,
CK_BYTE_PTR pWrappedKey, CK_ULONG_PTR pulWrappedKeyLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1186,7 +1175,7 @@
CK_ULONG pulWrappedKeyLen, CK_ATTRIBUTE_PTR pTemplate,
CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1195,14 +1184,14 @@
CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate,
CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
static CK_RV
test_C_SeedRandom (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, CK_ULONG ulSeedLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
@@ -1210,7 +1199,7 @@
test_C_GenerateRandom (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pRandomData,
CK_ULONG ulRandomLen)
{
- fail ("Not yet used by library");
+ g_assert_not_reached (); /* Not yet used by library */
return CKR_FUNCTION_NOT_SUPPORTED;
}
Modified: trunk/gp11/tests/gp11-test.h
==============================================================================
--- trunk/gp11/tests/gp11-test.h (original)
+++ trunk/gp11/tests/gp11-test.h Mon Jul 14 23:32:02 2008
@@ -4,14 +4,14 @@
#include "gp11.h"
#define FAIL_RES(res, e) do { \
- fail_if (res ? TRUE : FALSE, "should have failed"); \
- fail_unless ((e) && (e)->message, "error should be set"); \
+ g_assert ((res) ? FALSE : TRUE); \
+ g_assert ((e) && (e)->message && "error should be set"); \
g_clear_error (&e); \
} while (0)
#define SUCCESS_RES(res, err) do { \
- if (!res) g_printerr ("error: %s\n", err && err->message ? err->message : ""); \
- fail_unless (res ? TRUE : FALSE, "should have succeeded"); \
+ if (!(res)) g_printerr ("error: %s\n", err && err->message ? err->message : ""); \
+ g_assert ((res) ? TRUE : FALSE && "should have succeeded"); \
g_clear_error (&err); \
} while(0)
Modified: trunk/gp11/tests/unit-test-gp11-attributes.c
==============================================================================
--- trunk/gp11/tests/unit-test-gp11-attributes.c (original)
+++ trunk/gp11/tests/unit-test-gp11-attributes.c Mon Jul 14 23:32:02 2008
@@ -1,6 +1,4 @@
-#include <check.h>
-
#include <glib.h>
#include <string.h>
@@ -15,12 +13,12 @@
{
GP11Attribute attr;
- fail_if (sizeof (attr) != sizeof (CK_ATTRIBUTE));
+ g_assert (sizeof (attr) == sizeof (CK_ATTRIBUTE));
gp11_attribute_init (&attr, ATTR_TYPE, ATTR_DATA, N_ATTR_DATA);
- fail_unless (attr.type == ATTR_TYPE);
- fail_unless (attr.length == N_ATTR_DATA);
- fail_unless (memcmp (attr.value, ATTR_DATA, attr.length) == 0);
+ g_assert (attr.type == ATTR_TYPE);
+ g_assert (attr.length == N_ATTR_DATA);
+ g_assert (memcmp (attr.value, ATTR_DATA, attr.length) == 0);
gp11_attribute_clear (&attr);
}
@@ -30,9 +28,9 @@
GP11Attribute attr;
gp11_attribute_init_boolean (&attr, ATTR_TYPE, TRUE);
- fail_unless (attr.type == ATTR_TYPE);
- fail_unless (attr.length == sizeof (CK_BBOOL));
- fail_unless (*((CK_BBOOL*)attr.value) == CK_TRUE);
+ g_assert (attr.type == ATTR_TYPE);
+ g_assert (attr.length == sizeof (CK_BBOOL));
+ g_assert (*((CK_BBOOL*)attr.value) == CK_TRUE);
gp11_attribute_clear (&attr);
}
@@ -49,9 +47,9 @@
memcpy (ck_date.day, "05", 2);
gp11_attribute_init_date (&attr, ATTR_TYPE, date);
g_date_free (date);
- fail_unless (attr.type == ATTR_TYPE);
- fail_unless (attr.length == sizeof (CK_DATE));
- fail_unless (memcmp (attr.value, &ck_date, attr.length) == 0);
+ g_assert (attr.type == ATTR_TYPE);
+ g_assert (attr.length == sizeof (CK_DATE));
+ g_assert (memcmp (attr.value, &ck_date, attr.length) == 0);
gp11_attribute_clear (&attr);
}
@@ -61,9 +59,9 @@
GP11Attribute attr;
gp11_attribute_init_ulong (&attr, ATTR_TYPE, 88);
- fail_unless (attr.type == ATTR_TYPE);
- fail_unless (attr.length == sizeof (CK_ULONG));
- fail_unless (*((CK_ULONG*)attr.value) == 88);
+ g_assert (attr.type == ATTR_TYPE);
+ g_assert (attr.length == sizeof (CK_ULONG));
+ g_assert (*((CK_ULONG*)attr.value) == 88);
gp11_attribute_clear (&attr);
}
@@ -73,9 +71,9 @@
GP11Attribute attr;
gp11_attribute_init_string (&attr, ATTR_TYPE, "a test string");
- fail_unless (attr.type == ATTR_TYPE);
- fail_unless (attr.length == strlen ("a test string"));
- fail_unless (memcmp (attr.value, "a test string", attr.length) == 0);
+ g_assert (attr.type == ATTR_TYPE);
+ g_assert (attr.length == strlen ("a test string"));
+ g_assert (memcmp (attr.value, "a test string", attr.length) == 0);
gp11_attribute_clear (&attr);
}
@@ -85,9 +83,9 @@
GP11Attribute *attr;
attr = gp11_attribute_new (ATTR_TYPE, ATTR_DATA, N_ATTR_DATA);
- fail_unless (attr->type == ATTR_TYPE);
- fail_unless (attr->length == N_ATTR_DATA);
- fail_unless (memcmp (attr->value, ATTR_DATA, attr->length) == 0);
+ g_assert (attr->type == ATTR_TYPE);
+ g_assert (attr->length == N_ATTR_DATA);
+ g_assert (memcmp (attr->value, ATTR_DATA, attr->length) == 0);
gp11_attribute_free (attr);
}
@@ -97,9 +95,9 @@
GP11Attribute *attr;
attr = gp11_attribute_new_boolean (ATTR_TYPE, TRUE);
- fail_unless (attr->type == ATTR_TYPE);
- fail_unless (attr->length == sizeof (CK_BBOOL));
- fail_unless (*((CK_BBOOL*)attr->value) == CK_TRUE);
+ g_assert (attr->type == ATTR_TYPE);
+ g_assert (attr->length == sizeof (CK_BBOOL));
+ g_assert (*((CK_BBOOL*)attr->value) == CK_TRUE);
gp11_attribute_free (attr);
}
@@ -116,9 +114,9 @@
memcpy (ck_date.day, "05", 2);
attr = gp11_attribute_new_date (ATTR_TYPE, date);
g_date_free (date);
- fail_unless (attr->type == ATTR_TYPE);
- fail_unless (attr->length == sizeof (CK_DATE));
- fail_unless (memcmp (attr->value, &ck_date, attr->length) == 0);
+ g_assert (attr->type == ATTR_TYPE);
+ g_assert (attr->length == sizeof (CK_DATE));
+ g_assert (memcmp (attr->value, &ck_date, attr->length) == 0);
gp11_attribute_free (attr);
}
@@ -128,9 +126,9 @@
GP11Attribute *attr;
attr = gp11_attribute_new_ulong (ATTR_TYPE, 88);
- fail_unless (attr->type == ATTR_TYPE);
- fail_unless (attr->length == sizeof (CK_ULONG));
- fail_unless (*((CK_ULONG*)attr->value) == 88);
+ g_assert (attr->type == ATTR_TYPE);
+ g_assert (attr->length == sizeof (CK_ULONG));
+ g_assert (*((CK_ULONG*)attr->value) == 88);
gp11_attribute_free (attr);
}
@@ -140,9 +138,9 @@
GP11Attribute *attr;
attr = gp11_attribute_new_string (ATTR_TYPE, "a test string");
- fail_unless (attr->type == ATTR_TYPE);
- fail_unless (attr->length == strlen ("a test string"));
- fail_unless (memcmp (attr->value, "a test string", attr->length) == 0);
+ g_assert (attr->type == ATTR_TYPE);
+ g_assert (attr->length == strlen ("a test string"));
+ g_assert (memcmp (attr->value, "a test string", attr->length) == 0);
gp11_attribute_free (attr);
}
@@ -152,7 +150,7 @@
GP11Attribute *attr;
attr = gp11_attribute_new_boolean (ATTR_TYPE, TRUE);
- fail_unless (gp11_attribute_get_boolean (attr) == TRUE);
+ g_assert (gp11_attribute_get_boolean (attr) == TRUE);
gp11_attribute_free (attr);
}
@@ -168,7 +166,7 @@
memcpy (ck_date.day, "05", 2);
attr = gp11_attribute_new_date (ATTR_TYPE, date);
date2 = gp11_attribute_get_date (attr);
- fail_unless (g_date_compare (date, date2) == 0);
+ g_assert (g_date_compare (date, date2) == 0);
g_date_free (date);
g_date_free (date2);
gp11_attribute_free (attr);
@@ -179,7 +177,7 @@
GP11Attribute *attr;
attr = gp11_attribute_new_ulong (ATTR_TYPE, 88);
- fail_unless (gp11_attribute_get_ulong (attr) == 88);
+ g_assert (gp11_attribute_get_ulong (attr) == 88);
gp11_attribute_free (attr);
}
@@ -190,14 +188,14 @@
attr = gp11_attribute_new_string (ATTR_TYPE, "a test string");
value = gp11_attribute_get_string (attr);
- fail_unless (strcmp ("a test string", value) == 0);
+ g_assert (strcmp ("a test string", value) == 0);
g_free (value);
gp11_attribute_free (attr);
/* Should be able to store null strings */
attr = gp11_attribute_new_string (ATTR_TYPE, NULL);
value = gp11_attribute_get_string (attr);
- fail_unless (value == NULL);
+ g_assert (value == NULL);
gp11_attribute_free (attr);
}
@@ -208,13 +206,13 @@
gp11_attribute_init_ulong (&attr, ATTR_TYPE, 88);
dup = gp11_attribute_dup (&attr);
gp11_attribute_clear (&attr);
- fail_unless (gp11_attribute_get_ulong (dup) == 88);
- fail_unless (dup->type == ATTR_TYPE);
+ g_assert (gp11_attribute_get_ulong (dup) == 88);
+ g_assert (dup->type == ATTR_TYPE);
gp11_attribute_free (dup);
/* Should be able to dup null */
dup = gp11_attribute_dup (NULL);
- fail_if (dup != NULL);
+ g_assert (dup == NULL);
}
DEFINE_TEST(copy_attribute)
@@ -224,8 +222,8 @@
gp11_attribute_init_ulong (&attr, ATTR_TYPE, 88);
gp11_attribute_init_copy (©, &attr);
gp11_attribute_clear (&attr);
- fail_unless (gp11_attribute_get_ulong (©) == 88);
- fail_unless (copy.type == ATTR_TYPE);
+ g_assert (gp11_attribute_get_ulong (©) == 88);
+ g_assert (copy.type == ATTR_TYPE);
gp11_attribute_clear (©);
}
@@ -234,8 +232,8 @@
GP11Attributes *attrs;
attrs = gp11_attributes_new ();
- fail_if (attrs == NULL);
- fail_unless (gp11_attributes_count (attrs) == 0);
+ g_assert (attrs != NULL);
+ g_assert (gp11_attributes_count (attrs) == 0);
gp11_attributes_ref (attrs);
gp11_attributes_unref (attrs);
@@ -253,35 +251,35 @@
gchar *value;
GDate *date, *check;
- fail_if (attrs == NULL);
- fail_unless (gp11_attributes_count (attrs) == 5);
+ g_assert (attrs != NULL);
+ g_assert (gp11_attributes_count (attrs) == 5);
attr = gp11_attributes_at (attrs, 0);
- fail_unless (attr->type == 0);
- fail_unless (gp11_attribute_get_boolean (attr) == TRUE);
+ g_assert (attr->type == 0);
+ g_assert (gp11_attribute_get_boolean (attr) == TRUE);
attr = gp11_attributes_at (attrs, 1);
- fail_unless (attr->type == 101);
- fail_unless (gp11_attribute_get_ulong (attr) == 888);
+ g_assert (attr->type == 101);
+ g_assert (gp11_attribute_get_ulong (attr) == 888);
attr = gp11_attributes_at (attrs, 2);
- fail_unless (attr->type == 202);
+ g_assert (attr->type == 202);
value = gp11_attribute_get_string (attr);
- fail_unless (strcmp (value, "string") == 0);
+ g_assert (strcmp (value, "string") == 0);
g_free (value);
attr = gp11_attributes_at (attrs, 3);
- fail_unless (attr->type == 303);
+ g_assert (attr->type == 303);
check = g_date_new_dmy (11, 12, 2008);
date = gp11_attribute_get_date (attr);
- fail_unless (g_date_compare (date, check) == 0);
+ g_assert (g_date_compare (date, check) == 0);
g_date_free (date);
g_date_free (check);
attr = gp11_attributes_at (attrs, 4);
- fail_unless (attr->type == 404);
- fail_unless (attr->length == N_ATTR_DATA);
- fail_unless (memcmp (attr->value, ATTR_DATA, N_ATTR_DATA) == 0);
+ g_assert (attr->type == 404);
+ g_assert (attr->length == N_ATTR_DATA);
+ g_assert (memcmp (attr->value, ATTR_DATA, N_ATTR_DATA) == 0);
}
DEFINE_TEST(newv_attributes)
@@ -335,6 +333,7 @@
gp11_attributes_unref (attrs);
}
+#if 0
DEFINE_ABORT(bad_length)
{
GP11Attributes *attrs;
@@ -345,6 +344,7 @@
gp11_attributes_unref (attrs);
}
+#endif
DEFINE_TEST(add_data_attributes)
{
@@ -412,28 +412,28 @@
-1);
attr = gp11_attributes_find (attrs, 404);
- fail_if (attr == NULL);
- fail_unless (attr->length == N_ATTR_DATA);
- fail_unless (memcmp (attr->value, ATTR_DATA, N_ATTR_DATA) == 0);
+ g_assert (attr != NULL);
+ g_assert (attr->length == N_ATTR_DATA);
+ g_assert (memcmp (attr->value, ATTR_DATA, N_ATTR_DATA) == 0);
ret = gp11_attributes_find_boolean (attrs, 0, &bvalue);
- fail_unless (ret == TRUE);
- fail_unless (bvalue == TRUE);
+ g_assert (ret == TRUE);
+ g_assert (bvalue == TRUE);
ret = gp11_attributes_find_ulong (attrs, 101, &uvalue);
- fail_unless (ret == TRUE);
- fail_unless (uvalue == 888);
+ g_assert (ret == TRUE);
+ g_assert (uvalue == 888);
ret = gp11_attributes_find_string (attrs, 202, &svalue);
- fail_unless (ret == TRUE);
- fail_if (svalue == NULL);
- fail_unless (strcmp (svalue, "string") == 0);
+ g_assert (ret == TRUE);
+ g_assert (svalue != NULL);
+ g_assert (strcmp (svalue, "string") == 0);
g_free (svalue);
ret = gp11_attributes_find_date (attrs, 303, &check);
- fail_unless (ret == TRUE);
- fail_if (check == NULL);
- fail_unless (g_date_compare (date, check) == 0);
+ g_assert (ret == TRUE);
+ g_assert (check != NULL);
+ g_assert (g_date_compare (date, check) == 0);
g_date_free (check);
gp11_attributes_unref (attrs);
Modified: trunk/gp11/tests/unit-test-gp11-module.c
==============================================================================
--- trunk/gp11/tests/unit-test-gp11-module.c (original)
+++ trunk/gp11/tests/unit-test-gp11-module.c Mon Jul 14 23:32:02 2008
@@ -1,6 +1,4 @@
-#include <check.h>
-
#include <glib.h>
#include <string.h>
@@ -43,8 +41,8 @@
gchar *path;
g_object_get (module, "module-path", &path, NULL);
- fail_unless (path != NULL, "no module-path");
- fail_unless (strcmp (".libs/libgp11-test-module.so", path) == 0, "module path wrong");
+ g_assert (path != NULL && "no module-path");
+ g_assert (strcmp (".libs/libgp11-test-module.so", path) == 0 && "module path wrong");
g_free (path);
}
@@ -53,15 +51,15 @@
GP11ModuleInfo *info;
info = gp11_module_get_info (module);
- fail_unless (info != NULL, "no module info");
+ g_assert (info != NULL && "no module info");
- fail_unless (info->pkcs11_version_major == CRYPTOKI_VERSION_MAJOR, "wrong major version");
- fail_unless (info->pkcs11_version_minor == CRYPTOKI_VERSION_MINOR, "wrong minor version");
- fail_unless (strcmp ("TEST MANUFACTURER", info->manufacturer_id) == 0);
- fail_unless (strcmp ("TEST LIBRARY", info->library_description) == 0);
- fail_unless (0 == info->flags);
- fail_unless (45 == info->library_version_major);
- fail_unless (145 == info->library_version_minor);
+ g_assert (info->pkcs11_version_major == CRYPTOKI_VERSION_MAJOR && "wrong major version");
+ g_assert (info->pkcs11_version_minor == CRYPTOKI_VERSION_MINOR && "wrong minor version");
+ g_assert (strcmp ("TEST MANUFACTURER", info->manufacturer_id) == 0);
+ g_assert (strcmp ("TEST LIBRARY", info->library_description) == 0);
+ g_assert (0 == info->flags);
+ g_assert (45 == info->library_version_major);
+ g_assert (145 == info->library_version_minor);
gp11_module_info_free (info);
}
Modified: trunk/gp11/tests/unit-test-gp11-object.c
==============================================================================
--- trunk/gp11/tests/unit-test-gp11-object.c (original)
+++ trunk/gp11/tests/unit-test-gp11-object.c Mon Jul 14 23:32:02 2008
@@ -23,7 +23,7 @@
SUCCESS_RES (module, err);
slots = gp11_module_get_slots (module, TRUE);
- fail_if (slots == NULL);
+ g_assert (slots != NULL);
slot = GP11_SLOT (slots->data);
g_object_ref (slot);
@@ -34,7 +34,7 @@
/* Our module always exports a token object with this */
object = gp11_object_from_handle (session, 2);
- fail_if (object == NULL);
+ g_assert (object != NULL);
}
DEFINE_TEARDOWN(prep_object)
@@ -51,11 +51,11 @@
GP11Module *mod;
CK_OBJECT_HANDLE handle;
g_object_get (object, "session", &sess, "module", &mod, "handle", &handle, NULL);
- fail_unless (sess == session);
+ g_assert (sess == session);
g_object_unref (session);
- fail_unless (module == mod);
+ g_assert (module == mod);
g_object_unref (mod);
- fail_unless (handle == 2);
+ g_assert (handle == 2);
}
static void
@@ -81,7 +81,7 @@
CKA_VALUE, 4, "BLAH",
-1);
SUCCESS_RES (object, err);
- fail_unless (GP11_IS_OBJECT (object));
+ g_assert (GP11_IS_OBJECT (object));
if (object) {
last_handle = object->handle;
@@ -96,11 +96,11 @@
-1);
object = gp11_session_create_object_full (session, attrs, NULL, &err);
- fail_unless (GP11_IS_OBJECT (object));
+ g_assert (GP11_IS_OBJECT (object));
SUCCESS_RES (object, err);
if (object) {
- fail_if (last_handle == object->handle);
+ g_assert (last_handle != object->handle);
last_handle = object->handle;
g_object_unref (object);
}
@@ -108,12 +108,12 @@
/* Using async */
gp11_session_create_object_async (session, attrs, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
object = gp11_session_create_object_finish (session, result, &err);
g_object_unref (result);
SUCCESS_RES (object, err);
- fail_unless (GP11_IS_OBJECT (object));
+ g_assert (GP11_IS_OBJECT (object));
if (object)
g_object_unref (object);
@@ -134,7 +134,7 @@
CKA_TOKEN, GP11_BOOLEAN, CK_TRUE,
-1);
SUCCESS_RES (object, err);
- fail_unless (GP11_IS_OBJECT (object));
+ g_assert (GP11_IS_OBJECT (object));
if (!object)
return;
@@ -150,7 +150,7 @@
CKA_TOKEN, GP11_BOOLEAN, CK_TRUE,
-1);
SUCCESS_RES (object, err);
- fail_unless (GP11_IS_OBJECT (object));
+ g_assert (GP11_IS_OBJECT (object));
if (!object)
return;
@@ -166,7 +166,7 @@
CKA_TOKEN, GP11_BOOLEAN, CK_TRUE,
-1);
SUCCESS_RES (object, err);
- fail_unless (GP11_IS_OBJECT (object));
+ g_assert (GP11_IS_OBJECT (object));
if (!object)
return;
@@ -174,7 +174,7 @@
/* Using async */
gp11_object_destroy_async (object, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
ret = gp11_object_destroy_finish (object, result, &err);
g_object_unref (result);
@@ -195,8 +195,8 @@
attrs = gp11_object_get (object, &err, CKA_CLASS, CKA_LABEL, -1);
SUCCESS_RES (attrs, err);
if (attrs != NULL) {
- fail_unless (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
- fail_unless (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
+ g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
+ g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
g_free (value); value = NULL;
gp11_attributes_unref (attrs);
}
@@ -205,8 +205,8 @@
attrs = gp11_object_get_full (object, types, 2, NULL, &err);
SUCCESS_RES (attrs, err);
if (attrs != NULL) {
- fail_unless (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
- fail_unless (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
+ g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
+ g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
g_free (value); value = NULL;
gp11_attributes_unref (attrs);
}
@@ -214,14 +214,14 @@
/* Async */
gp11_object_get_async (object, types, 2, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
attrs = gp11_object_get_finish (object, result, &err);
g_object_unref (result);
SUCCESS_RES (attrs, err);
if (attrs != NULL) {
- fail_unless (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
- fail_unless (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
+ g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
+ g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
g_free (value); value = NULL;
gp11_attributes_unref (attrs);
}
@@ -237,7 +237,7 @@
attr = gp11_object_get_one (object, CKA_CLASS, &err);
SUCCESS_RES (attr, err);
if (attr != NULL) {
- fail_unless (attr->type == CKA_CLASS && gp11_attribute_get_ulong (attr) == CKO_DATA);
+ g_assert (attr->type == CKA_CLASS && gp11_attribute_get_ulong (attr) == CKO_DATA);
gp11_attribute_free (attr);
}
@@ -245,20 +245,20 @@
attr = gp11_object_get_one_full (object, CKA_CLASS, NULL, &err);
SUCCESS_RES (attr, err);
if (attr != NULL) {
- fail_unless (attr->type == CKA_CLASS && gp11_attribute_get_ulong (attr) == CKO_DATA);
+ g_assert (attr->type == CKA_CLASS && gp11_attribute_get_ulong (attr) == CKO_DATA);
gp11_attribute_free (attr);
}
/* Async */
gp11_object_get_one_async (object, CKA_CLASS, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
attr = gp11_object_get_one_finish (object, result, &err);
g_object_unref (result);
SUCCESS_RES (attr, err);
if (attr != NULL) {
- fail_unless (attr->type == CKA_CLASS && gp11_attribute_get_ulong (attr) == CKO_DATA);
+ g_assert (attr->type == CKA_CLASS && gp11_attribute_get_ulong (attr) == CKO_DATA);
gp11_attribute_free (attr);
}
}
@@ -280,8 +280,8 @@
SUCCESS_RES (ret, err);
if (ret) {
attrs = gp11_object_get (object, &err, CKA_CLASS, CKA_LABEL, -1);
- fail_unless (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == 5);
- fail_unless (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "CHANGE ONE") == 0);
+ g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == 5);
+ g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "CHANGE ONE") == 0);
g_free (value); value = NULL;
gp11_attributes_unref (attrs);
}
@@ -296,8 +296,8 @@
SUCCESS_RES (ret, err);
if (ret) {
attrs = gp11_object_get (object, &err, CKA_CLASS, CKA_LABEL, -1);
- fail_unless (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == 6);
- fail_unless (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "CHANGE TWO") == 0);
+ g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == 6);
+ g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "CHANGE TWO") == 0);
g_free (value); value = NULL;
gp11_attributes_unref (attrs);
}
@@ -309,15 +309,15 @@
/* Async */
gp11_object_set_async (object, templ, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
ret = gp11_object_set_finish (object, result, &err);
g_object_unref (result);
SUCCESS_RES (ret, err);
if (ret) {
attrs = gp11_object_get (object, &err, CKA_CLASS, CKA_LABEL, -1);
- fail_unless (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == 7);
- fail_unless (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "CHANGE THREE") == 0);
+ g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == 7);
+ g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "CHANGE THREE") == 0);
g_free (value); value = NULL;
gp11_attributes_unref (attrs);
}
@@ -346,24 +346,24 @@
/* Simple, "TEST LABEL" */
objects = gp11_session_find_objects (session, &err, CKA_LABEL, GP11_STRING, "UNIQUE LABEL", -1);
SUCCESS_RES (objects, err);
- fail_unless (g_list_length (objects) == 1);
+ g_assert (g_list_length (objects) == 1);
gp11_list_unref_free (objects);
/* Full, All */
templ = gp11_attributes_new ();
objects = gp11_session_find_objects_full (session, templ, NULL, &err);
SUCCESS_RES (objects, err);
- fail_unless (g_list_length (objects) > 1);
+ g_assert (g_list_length (objects) > 1);
gp11_list_unref_free (objects);
/* Async, None */
gp11_attributes_add_string (templ, CKA_LABEL, "blah blah");
gp11_session_find_objects_async (session, templ, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
objects = gp11_session_find_objects_finish (session, result, &err);
g_object_unref (result);
- fail_unless (objects == NULL);
+ g_assert (objects == NULL);
gp11_list_unref_free (objects);
}
Modified: trunk/gp11/tests/unit-test-gp11-session.c
==============================================================================
--- trunk/gp11/tests/unit-test-gp11-session.c (original)
+++ trunk/gp11/tests/unit-test-gp11-session.c Mon Jul 14 23:32:02 2008
@@ -22,7 +22,7 @@
SUCCESS_RES (module, err);
slots = gp11_module_get_slots (module, TRUE);
- fail_if (slots == NULL);
+ g_assert (slots != NULL);
slot = GP11_SLOT (slots->data);
g_object_ref (slot);
@@ -45,24 +45,23 @@
guint handle;
g_object_get (session, "module", &mod, "handle", &handle, NULL);
- fail_unless (mod == module);
+ g_assert (mod == module);
g_object_unref (mod);
- fail_unless (handle != 0);
- fail_unless (session->handle == handle);
+ g_assert (handle != 0);
+ g_assert (session->handle == handle);
}
DEFINE_TEST(session_info)
{
GP11SessionInfo *info;
- g_printerr ("session_info");
info = gp11_session_get_info (session);
- fail_unless (info != NULL, "no session info");
+ g_assert (info != NULL && "no session info");
- fail_unless (info->slot_id == slot->handle);
- fail_unless ((info->flags & CKF_SERIAL_SESSION) == CKF_SERIAL_SESSION);
- fail_unless (info->device_error == 1414);
+ g_assert (info->slot_id == slot->handle);
+ g_assert ((info->flags & CKF_SERIAL_SESSION) == CKF_SERIAL_SESSION);
+ g_assert (info->device_error == 1414);
gp11_session_info_free (info);
}
@@ -88,7 +87,7 @@
gp11_slot_open_session_async (slot, 0, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
/* Get the result */
sess = gp11_slot_open_session_finish (slot, result, &err);
@@ -120,7 +119,7 @@
/* login async */
gp11_session_login_async (session, CKU_USER, (guchar*)"booo", 4, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
ret = gp11_session_login_finish (session, result, &err);
SUCCESS_RES (ret, err);
@@ -131,7 +130,7 @@
/* logout async */
gp11_session_logout_async (session, NULL, fetch_async_result, &result);
WAIT_UNTIL (result);
- fail_if (result == NULL);
+ g_assert (result != NULL);
ret = gp11_session_logout_finish (session, result, &err);
SUCCESS_RES (ret, err);
Modified: trunk/gp11/tests/unit-test-gp11-slot.c
==============================================================================
--- trunk/gp11/tests/unit-test-gp11-slot.c (original)
+++ trunk/gp11/tests/unit-test-gp11-slot.c Mon Jul 14 23:32:02 2008
@@ -1,6 +1,4 @@
-#include <check.h>
-
#include <glib.h>
#include <string.h>
@@ -20,7 +18,7 @@
SUCCESS_RES (module, err);
slots = gp11_module_get_slots (module, TRUE);
- fail_if (slots == NULL);
+ g_assert (slots != NULL);
slot = GP11_SLOT (slots->data);
g_object_ref (slot);
@@ -41,46 +39,46 @@
GList *slots, *l;
slots = gp11_module_get_slots (module, FALSE);
- fail_unless (2 == g_list_length (slots), "wrong number of slots returned");
- fail_unless (GP11_IS_SLOT (slots->data), "missing slot one");
- fail_unless (GP11_IS_SLOT (slots->next->data), "missing slot two");
+ g_assert (2 == g_list_length (slots) && "wrong number of slots returned");
+ g_assert (GP11_IS_SLOT (slots->data) && "missing slot one");
+ g_assert (GP11_IS_SLOT (slots->next->data) && "missing slot two");
for (l = slots; l; l = g_list_next (l)) {
info = gp11_slot_get_info (GP11_SLOT (l->data));
- fail_unless (info != NULL, "no slot info");
+ g_assert (info != NULL && "no slot info");
- fail_unless (strcmp("TEST MANUFACTURER", info->manufacturer_id) == 0);
- fail_unless (strcmp("TEST SLOT", info->slot_description) == 0);
- fail_unless (55 == info->hardware_version_major);
- fail_unless (155 == info->hardware_version_minor);
- fail_unless (65 == info->firmware_version_major);
- fail_unless (165 == info->firmware_version_minor);
+ g_assert (strcmp("TEST MANUFACTURER", info->manufacturer_id) == 0);
+ g_assert (strcmp("TEST SLOT", info->slot_description) == 0);
+ g_assert (55 == info->hardware_version_major);
+ g_assert (155 == info->hardware_version_minor);
+ g_assert (65 == info->firmware_version_major);
+ g_assert (165 == info->firmware_version_minor);
gp11_slot_info_free (info);
if (info->flags & CKF_TOKEN_PRESENT) {
token = gp11_slot_get_token_info (slot);
- fail_if (token == NULL, "no token info");
+ g_assert (token != NULL && "no token info");
- fail_unless (strcmp ("TEST MANUFACTURER", token->manufacturer_id) == 0);
- fail_unless (strcmp ("TEST LABEL", token->label) == 0);
- fail_unless (strcmp ("TEST MODEL", token->model) == 0);
- fail_unless (strcmp ("TEST SERIAL", token->serial_number) == 0);
- fail_unless (1 == token->max_session_count);
- fail_unless (2 == token->session_count);
- fail_unless (3 == token->max_rw_session_count);
- fail_unless (4 == token->rw_session_count);
- fail_unless (5 == token->max_pin_len);
- fail_unless (6 == token->min_pin_len);
- fail_unless (7 == token->total_public_memory);
- fail_unless (8 == token->free_public_memory);
- fail_unless (9 == token->total_private_memory);
- fail_unless (10 == token->free_private_memory);
- fail_unless (75 == token->hardware_version_major);
- fail_unless (175 == token->hardware_version_minor);
- fail_unless (85 == token->firmware_version_major);
- fail_unless (185 == token->firmware_version_minor);
- fail_unless (927645599 == token->utc_time);
+ g_assert (strcmp ("TEST MANUFACTURER", token->manufacturer_id) == 0);
+ g_assert (strcmp ("TEST LABEL", token->label) == 0);
+ g_assert (strcmp ("TEST MODEL", token->model) == 0);
+ g_assert (strcmp ("TEST SERIAL", token->serial_number) == 0);
+ g_assert (1 == token->max_session_count);
+ g_assert (2 == token->session_count);
+ g_assert (3 == token->max_rw_session_count);
+ g_assert (4 == token->rw_session_count);
+ g_assert (5 == token->max_pin_len);
+ g_assert (6 == token->min_pin_len);
+ g_assert (7 == token->total_public_memory);
+ g_assert (8 == token->free_public_memory);
+ g_assert (9 == token->total_private_memory);
+ g_assert (10 == token->free_private_memory);
+ g_assert (75 == token->hardware_version_major);
+ g_assert (175 == token->hardware_version_minor);
+ g_assert (85 == token->firmware_version_major);
+ g_assert (185 == token->firmware_version_minor);
+ g_assert (927645599 == token->utc_time);
gp11_token_info_free (token);
}
@@ -95,8 +93,8 @@
CK_SLOT_ID slot_id;
g_object_get (slot, "module", &mod, "handle", &slot_id, NULL);
- fail_unless (mod == module);
- fail_unless (slot_id == 52);
+ g_assert (mod == module);
+ g_assert (slot_id == 52);
g_object_unref (mod);
}
@@ -107,12 +105,12 @@
GP11MechanismInfo *info;
mechs = gp11_slot_get_mechanisms (slot);
- fail_unless (2 == g_slist_length (mechs), "wrong number of mech types returned");
+ g_assert (2 == g_slist_length (mechs) && "wrong number of mech types returned");
for (l = mechs; l; l = g_slist_next (l)) {
info = gp11_slot_get_mechanism_info (slot, GPOINTER_TO_UINT (l->data));
- fail_unless (info != NULL, "no mech info returned");
+ g_assert (info != NULL && "no mech info returned");
gp11_mechanism_info_free (info);
}
Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am (original)
+++ trunk/tests/Makefile.am Mon Jul 14 23:32:02 2008
@@ -3,9 +3,10 @@
ca-example \
cu-test \
test-helpers.c test-helpers.h \
- prep-tests.sh \
+ gtest-helpers.c gtest-helpers.h \
+ prep-tests.sh prep-gtest.sh \
run-tests.sh \
- test.make
+ test.make gtest.make
INCLUDES= \
-I$(top_srcdir) \
@@ -54,7 +55,7 @@
run: run-auto
run-auto:
- sh run-tests.sh $(top_srcdir) run-auto-test
+ sh run-tests.sh $(top_srcdir) test-auto
run-prompt:
- sh run-tests.sh $(top_srcdir) run-prompt-test
+ sh run-tests.sh $(top_srcdir) test-auto
Copied: trunk/tests/gtest-helpers.c (from r1175, /trunk/tests/check-helpers.c)
==============================================================================
--- /trunk/tests/check-helpers.c (original)
+++ trunk/tests/gtest-helpers.c Mon Jul 14 23:32:02 2008
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* test-helpers.c: Common functions called from check unit tests
+/* test-helpers.c: Common functions called from gtest unit tests
Copyright (C) 2008 Stefan Walter
@@ -21,7 +21,7 @@
Author: Stef Walter <stef memberwebs com>
*/
-/* This file is included into the main .c file for each check unit-test program */
+/* This file is included into the main .c file for each gtest unit-test program */
#include <glib.h>
#include <gtk/gtk.h>
@@ -30,17 +30,12 @@
#include <stdlib.h>
#include <string.h>
-#include <check.h>
-
-#include "check-helpers.h"
+#include "gtest-helpers.h"
#include "common/gkr-secure-memory.h"
static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
-/* Used from the tests sometimes */
-SRunner *srunner = NULL;
-
void gkr_memory_lock (void)
{
g_static_mutex_lock (&memory_mutex);
@@ -95,13 +90,6 @@
return mainloop;
}
-void
-test_quiet_abort_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
- const gchar *message, gpointer user_data)
-{
- abort();
-}
-
static void
chdir_base_dir (char* argv0)
{
@@ -123,8 +111,6 @@
{
GLogLevelFlags fatal_mask;
const gchar* envi;
- int number_failed;
- Suite *suite;
g_thread_init (NULL);
@@ -137,7 +123,8 @@
}
chdir_base_dir (argv[0]);
- gtk_init(&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+ gtk_init (&argc, &argv);
mainloop = g_main_loop_new (NULL, FALSE);
#ifndef EXTERNAL_TEST
@@ -150,12 +137,6 @@
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
- suite = test_suite_create ();
- srunner = srunner_create (suite);
- srunner_run_all (srunner, CK_NORMAL);
- number_failed = srunner_ntests_failed (srunner);
- srunner_free (srunner);
- srunner = NULL;
-
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+ initialize_tests ();
+ return g_test_run ();
}
Copied: trunk/tests/gtest-helpers.h (from r1175, /trunk/tests/check-helpers.h)
==============================================================================
--- /trunk/tests/check-helpers.h (original)
+++ trunk/tests/gtest-helpers.h Mon Jul 14 23:32:02 2008
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* check-helpers.h: Declarations for common functions called from check unit tests
+/* gtest-helpers.h: Declarations for common functions called from gtest unit tests
Copyright (C) 2008 Stefan Walter
@@ -21,8 +21,8 @@
Author: Stef Walter <stef memberwebs com>
*/
-#ifndef CHECK_HELPERS_H_
-#define CHECK_HELPERS_H_
+#ifndef GTEST_HELPERS_H_
+#define GTEST_HELPERS_H_
#include <glib.h>
@@ -30,7 +30,21 @@
void test_mainloop_run (int timeout);
GMainLoop* test_mainloop_get (void);
-void test_quiet_abort_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
- const gchar *message, gpointer user_data);
+#define DECLARE_SETUP(x) \
+ void setup_##x(int *v, gconstpointer d)
+#define DEFINE_SETUP(x) \
+ void setup_##x(int *__unused G_GNUC_UNUSED, gconstpointer __data G_GNUC_UNUSED)
+
+#define DECLARE_TEARDOWN(x) \
+ void teardown_##x(int *v, gconstpointer d)
+#define DEFINE_TEARDOWN(x) \
+ void teardown_##x(int *__unused G_GNUC_UNUSED, gconstpointer __data G_GNUC_UNUSED)
+
+#define DECLARE_TEST(x) \
+ void test_##x(int *v, gconstpointer d)
+#define DEFINE_TEST(x) \
+ void test_##x(int *__unused G_GNUC_UNUSED, gconstpointer __data G_GNUC_UNUSED)
-#endif /*CHECK_HELPERS_H_*/
+/* #define DEFINE_ABORT(x) void abort_x(void *__unused G_GNUC_UNUSED, gconstpointer __data G_GNUC_UNUSED)' */
+
+#endif /* GTEST_HELPERS_H_ */
Copied: trunk/tests/gtest.make (from r1175, /trunk/tests/check.make)
==============================================================================
--- /trunk/tests/check.make (original)
+++ trunk/tests/gtest.make Mon Jul 14 23:32:02 2008
@@ -11,21 +11,19 @@
-I$(top_srcdir)/daemon \
-I$(top_builddir) \
$(GTK_CFLAGS) \
- $(GLIB_CFLAGS) \
- $(CHECK_CFLAGS)
+ $(GLIB_CFLAGS)
LIBS = \
$(GTK_LIBS) \
$(GLIB_LIBS) \
- $(GTHREAD_LIBS) \
- $(CHECK_LIBS)
+ $(GTHREAD_LIBS)
noinst_PROGRAMS= \
run-auto-test \
run-prompt-test
-run-auto-test.c: $(UNIT_AUTO) Makefile.am $(top_srcdir)/tests/prep-check.sh
- sh $(top_srcdir)/tests/prep-check.sh -b run-auto-test $(UNIT_AUTO)
+run-auto-test.c: $(UNIT_AUTO) Makefile.am $(top_srcdir)/tests/prep-gtest.sh
+ sh $(top_srcdir)/tests/prep-gtest.sh -b run-auto-test $(UNIT_AUTO)
run_auto_test_SOURCES = \
run-auto-test.c run-auto-test.h \
@@ -38,8 +36,8 @@
run_auto_test_CFLAGS = \
$(UNIT_FLAGS)
-run-prompt-test.c: $(UNIT_PROMPT) Makefile.am $(top_srcdir)/tests/prep-check.sh
- sh $(top_srcdir)/tests/prep-check.sh -b run-prompt-test $(UNIT_PROMPT)
+run-prompt-test.c: $(UNIT_PROMPT) Makefile.am $(top_srcdir)/tests/prep-gtest.sh
+ sh $(top_srcdir)/tests/prep-gtest.sh -b run-prompt-test $(UNIT_PROMPT)
run_prompt_test_SOURCES = \
run-prompt-test.c run-prompt-test.h \
@@ -56,7 +54,7 @@
# Run the tests
test-auto: $(noinst_PROGRAMS)
- ./run-auto-test
+ gtester -k -m=slow ./run-auto-test
test-prompt: $(noinst_PROGRAMS)
- ./run-prompt-test
+ gtester -k -m=slow ./run-prompt-test
Copied: trunk/tests/prep-gtest.sh (from r1175, /trunk/tests/prep-check.sh)
==============================================================================
--- /trunk/tests/prep-check.sh (original)
+++ trunk/tests/prep-gtest.sh Mon Jul 14 23:32:02 2008
@@ -7,102 +7,86 @@
usage()
{
- echo "usage: prep-check.sh -b base-name files.c ..." >&2
+ echo "usage: prep-gtest.sh -b base-name files.c ..." >&2
exit 2
}
# --------------------------------------------------------------------
# SOURCE FILE
+file_to_name()
+{
+ echo -n $1 | sed -e 's/unit-test-//' -e 's/\.c//'
+ # | tr -c 'a-zA-Z0-9' '_'
+}
+
build_header()
{
local _file
echo '/* This is auto-generated code. Edit at your own peril. */'
- # echo "#ifndef _${BASE}_H_"
- # echo "#define _${BASE}_H_"
- echo
- echo '#include <check.h>'
- echo
- echo 'extern SRunner *srunner;'
- echo
- echo '#define DEFINE_SETUP(x) void setup_##x(void)'
- echo '#define DEFINE_TEARDOWN(x) void teardown_##x(void)'
- echo '#define DEFINE_TEST(x) void x(void)'
- echo '#define DEFINE_ABORT(x) void x(void)'
+ echo '#include "tests/gtest-helpers.h"'
echo
+
for _file in $@; do
- sed -ne 's/.*DEFINE_SETUP(\([^)]\+\))/ void setup_\1(void);/p' $_file
- sed -ne 's/.*DEFINE_TEARDOWN(\([^)]\+\))/ void teardown_\1(void);/p' $_file
- sed -ne 's/.*DEFINE_TEST(\([^)]\+\))/ void \1(void);/p' $_file
- sed -ne 's/.*DEFINE_ABORT(\([^)]\+\))/ void \1(void);/p' $_file
+ sed -ne 's/.*DEFINE_SETUP(\([^)]\+\))/DECLARE_SETUP(\1);/p' $_file
+ sed -ne 's/.*DEFINE_TEARDOWN(\([^)]\+\))/DECLARE_TEARDOWN(\1);/p' $_file
+ sed -ne 's/.*DEFINE_TEST(\([^)]\+\))/DECLARE_TEST(\1);/p' $_file
+ # sed -ne 's/.*DEFINE_ABORT(\([^)]\+\))/DECLARE_ABORT(\1);/p' $_file
done
echo
- # echo "#endif"
}
build_source()
{
- local _tcases _file _name
+ local _tcases _file _name _setup _teardown
echo '/* This is auto-generated code. Edit at your own peril. */'
- echo '#include <check.h>'
- echo "#include \"tests/check-helpers.h\""
+ echo "#include \"tests/gtest-helpers.h\""
echo "#include \"$BASE.h\""
echo
# A test macro
- echo '#define WRAP_TEST(name) \'
- echo ' START_TEST(test_##name) { \'
- echo ' name (); \'
- echo ' } END_TEST'
-
- # Note that we can't run abort tests without CK_FORK
- echo '#define WRAP_ABORT(name) \'
- echo ' START_TEST(test_##name) { \'
- echo ' if (srunner_fork_status (srunner) == CK_NOFORK) return; \'
- echo ' GLogFunc old = g_log_set_default_handler (test_quiet_abort_log_handler, NULL); \'
- echo ' name (); \'
- echo ' g_log_set_default_handler (old, NULL); \'
- echo ' } END_TEST'
-
+ # echo '#define WRAP_ABORT(name) \'
+ # echo ' START_TEST(test_##name) { \'
+ # echo ' if (srunner_fork_status (srunner) == CK_NOFORK) return; \'
+ # echo ' GLogFunc old = g_log_set_default_handler (test_quiet_abort_log_handler, NULL); \'
+ # echo ' name (); \'
+ # echo ' g_log_set_default_handler (old, NULL); \'
+ # echo ' } END_TEST'
+
+ echo "static void initialize_tests (void) {"
# Include each file, and build a test case for it
_tcases=""
for _file in $@; do
- _name=`echo $_file | tr -c 'a-zA-Z0-9' '_'`
-
- # Include the test file
- # echo "#include \"$_file\""
- # echo
+ _name=`file_to_name $_file`
# Wrap each and every test
- sed -ne 's/.*DEFINE_TEST(\([^)]\+\)).*/WRAP_TEST (\1);/p' $_file
- sed -ne 's/.*DEFINE_ABORT(\([^)]\+\)).*/WRAP_ABORT (\1);/p' $_file
+ # sed -ne 's/.*DEFINE_TEST(\([^)]\+\)).*/WRAP_TEST (\1);/p' $_file
+ # sed -ne 's/.*DEFINE_ABORT(\([^)]\+\)).*/WRAP_ABORT (\1);/p' $_file
echo
+ # Calculate what our setup and teardowns are.
+ _setup=`sed -ne 's/.*DEFINE_SETUP(\([^)]\+\)).*/setup_\1/p' $_file || echo "NULL"`
+ if [ -z "$_setup" ]; then
+ _setup="NULL"
+ fi
+
+ _teardown=`sed -ne 's/.*DEFINE_TEARDOWN(\([^)]\+\)).*/teardown_\1/p' $_file`
+ if [ -z "$_teardown" ]; then
+ _teardown="NULL"
+ fi
+
# Add all tests to the test case
- echo "static TCase* tcase_$_name(void) {"
- _tcases="$_tcases $_name"
- echo " TCase *tc = tcase_create (\"X\");"
- sed -ne 's/.*DEFINE_SETUP(\([^)]\+\)).*/ tcase_add_checked_fixture (tc, setup_\1, teardown_\1);/p' $_file
- sed -ne 's/.*DEFINE_TEST(\([^)]\+\)).*/ tcase_add_test (tc, test_\1);/p' $_file
- sed -ne 's/.*DEFINE_ABORT(\([^)]\+\)).*/ tcase_add_test_raise_signal (tc, test_\1, 6);/p' $_file
- echo " return tc;"
- echo "}"
- echo
+ sed -ne "s/.*DEFINE_TEST(\([^)]\+\)).*/ g_test_add(\"\/$_name\/\1\", int, NULL, $_setup, test_\1, $_teardown);/p" $_file
+ # sed -ne 's/.*DEFINE_ABORT(\([^)]\+\)).*/ tcase_add_test_raise_signal (tc, test_\1, 6);/p' $_file
done
- echo "static Suite* test_suite_create (void) {"
- echo " Suite *s = suite_create (\"$BASE\");"
- for _name in $_tcases; do
- echo " suite_add_tcase (s, tcase_$_name());"
- done
- echo " return s;"
echo "}"
echo
- echo "#include \"tests/check-helpers.c\""
+ echo "#include \"tests/gtest-helpers.c\""
}
# --------------------------------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]