|
Packit Service |
3749ba |
/*
|
|
Packit Service |
3749ba |
* Copyright (c) 2012 Stefan Walter
|
|
Packit Service |
3749ba |
* Copyright (c) 2012 Red Hat Inc.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
3749ba |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
3749ba |
* are met:
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* * Redistributions of source code must retain the above
|
|
Packit Service |
3749ba |
* copyright notice, this list of conditions and the
|
|
Packit Service |
3749ba |
* following disclaimer.
|
|
Packit Service |
3749ba |
* * Redistributions in binary form must reproduce the
|
|
Packit Service |
3749ba |
* above copyright notice, this list of conditions and
|
|
Packit Service |
3749ba |
* the following disclaimer in the documentation and/or
|
|
Packit Service |
3749ba |
* other materials provided with the distribution.
|
|
Packit Service |
3749ba |
* * The names of contributors to this software may not be
|
|
Packit Service |
3749ba |
* used to endorse or promote products derived from this
|
|
Packit Service |
3749ba |
* software without specific prior written permission.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit Service |
3749ba |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit Service |
3749ba |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
Packit Service |
3749ba |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
Packit Service |
3749ba |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit Service |
3749ba |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
Packit Service |
3749ba |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
Packit Service |
3749ba |
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
Packit Service |
3749ba |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit Service |
3749ba |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
Packit Service |
3749ba |
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
Packit Service |
3749ba |
* DAMAGE.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Author: Stef Walter <stef@thewalter.net>
|
|
Packit Service |
3749ba |
*/
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "config.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "library.h"
|
|
Packit Service |
3749ba |
#include "p11-kit.h"
|
|
Packit Service |
3749ba |
#include "private.h"
|
|
Packit Service |
3749ba |
#include "virtual.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "test.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "mock.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include <sys/types.h>
|
|
Packit Service |
3749ba |
#include <assert.h>
|
|
Packit Service |
3749ba |
#include <string.h>
|
|
Packit Service |
3749ba |
#include <stdio.h>
|
|
Packit Service |
3749ba |
#include <stdlib.h>
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/*
|
|
Packit Service |
3749ba |
* test-managed.c is a pretty good test of the closure code, so we
|
|
Packit Service |
3749ba |
* just test a few things here.
|
|
Packit Service |
3749ba |
*/
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
typedef struct {
|
|
Packit Service |
3749ba |
p11_virtual virt;
|
|
Packit Service |
3749ba |
void *check;
|
|
Packit Service |
3749ba |
} Override;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static CK_RV
|
|
Packit Service |
3749ba |
override_initialize (CK_X_FUNCTION_LIST *self,
|
|
Packit Service |
3749ba |
CK_VOID_PTR args)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
Override *over = (Override *)self;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert_str_eq ("initialize-arg", args);
|
|
Packit Service |
3749ba |
assert_str_eq ("overide-arg", over->check);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/* An arbitrary error code to check */
|
|
Packit Service |
3749ba |
return CKR_NEED_TO_CREATE_THREADS;
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static bool test_destroyed = false;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_destroyer (void *data)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
assert (data == &mock_x_module_no_slots);
|
|
Packit Service |
3749ba |
assert (test_destroyed == false);
|
|
Packit Service |
3749ba |
test_destroyed = true;
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_initialize (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
CK_FUNCTION_LIST_PTR module;
|
|
Packit Service |
3749ba |
Override over = { };
|
|
Packit Service |
3749ba |
CK_RV rv;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_virtual_init (&over.virt, &p11_virtual_stack, &mock_x_module_no_slots, test_destroyer);
|
|
Packit Service |
3749ba |
over.virt.funcs.C_Initialize = override_initialize;
|
|
Packit Service |
3749ba |
over.check = "overide-arg";
|
|
Packit Service |
3749ba |
test_destroyed = false;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
module = p11_virtual_wrap (&over.virt, (p11_destroyer)p11_virtual_uninit);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (module);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
rv = (module->C_Initialize) ("initialize-arg");
|
|
Packit Service |
3749ba |
assert_num_eq (CKR_NEED_TO_CREATE_THREADS, rv);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_virtual_unwrap (module);
|
|
Packit Service |
3749ba |
assert_num_eq (true, test_destroyed);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_fall_through (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
CK_FUNCTION_LIST_PTR module;
|
|
Packit Service |
3749ba |
Override over = { };
|
|
Packit Service |
3749ba |
p11_virtual base;
|
|
Packit Service |
3749ba |
CK_RV rv;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_virtual_init (&base, &p11_virtual_base, &mock_module_no_slots, NULL);
|
|
Packit Service |
3749ba |
p11_virtual_init (&over.virt, &p11_virtual_stack, &base, NULL);
|
|
Packit Service |
3749ba |
over.virt.funcs.C_Initialize = override_initialize;
|
|
Packit Service |
3749ba |
over.check = "overide-arg";
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
module = p11_virtual_wrap (&over.virt, NULL);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (module);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
rv = (module->C_Initialize) ("initialize-arg");
|
|
Packit Service |
3749ba |
assert_num_eq (CKR_NEED_TO_CREATE_THREADS, rv);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/* All other functions should have just fallen through */
|
|
Packit Service |
3749ba |
assert_ptr_eq (mock_module_no_slots.C_Finalize, module->C_Finalize);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_virtual_unwrap (module);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_get_function_list (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
CK_FUNCTION_LIST_PTR module;
|
|
Packit Service |
3749ba |
CK_FUNCTION_LIST_PTR list;
|
|
Packit Service |
3749ba |
p11_virtual virt;
|
|
Packit Service |
3749ba |
CK_RV rv;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_virtual_init (&virt, &p11_virtual_base, &mock_module_no_slots, NULL);
|
|
Packit Service |
3749ba |
module = p11_virtual_wrap (&virt, NULL);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (module);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
rv = (module->C_GetFunctionList) (&list);
|
|
Packit Service |
3749ba |
assert_num_eq (CKR_OK, rv);
|
|
Packit Service |
3749ba |
assert_ptr_eq (module, list);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
rv = (module->C_GetFunctionList) (&list);
|
|
Packit Service |
3749ba |
assert_num_eq (CKR_OK, rv);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
rv = (module->C_GetFunctionList) (NULL);
|
|
Packit Service |
3749ba |
assert_num_eq (CKR_ARGUMENTS_BAD, rv);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_virtual_unwrap (module);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
int
|
|
Packit Service |
3749ba |
main (int argc,
|
|
Packit Service |
3749ba |
char *argv[])
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
mock_module_init ();
|
|
Packit Service |
3749ba |
p11_library_init ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_test (test_initialize, "/virtual/test_initialize");
|
|
Packit Service |
3749ba |
p11_test (test_fall_through, "/virtual/test_fall_through");
|
|
Packit Service |
3749ba |
p11_test (test_get_function_list, "/virtual/test_get_function_list");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
return p11_test_run (argc, argv);
|
|
Packit Service |
3749ba |
}
|