/[ascend]/trunk/base/generic/utilities/test/test_ascDynaLoad.c
ViewVC logotype

Annotation of /trunk/base/generic/utilities/test/test_ascDynaLoad.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (hide annotations) (download) (as text)
Mon Oct 31 03:39:15 2005 UTC (19 years, 6 months ago) by jds
File MIME type: text/x-csrc
File size: 6076 byte(s)
- jam build up and limping on Linux (finally).
- fixes to CUnit test suite to compile on Linux (still not operable, though).
1 jds 59 /*
2     * Unit test functions for ASCEND: utilities/ascDynaLoad.c
3     *
4     * Copyright (C) 2005 Jerry St.Clair
5     *
6     * This file is part of the Ascend Environment.
7     *
8     * The Ascend Environment is free software; you can redistribute it
9     * and/or modify it under the terms of the GNU General Public License as
10     * published by the Free Software Foundation; either version 2 of the
11     * License, or (at your option) any later version.
12     *
13     * The Ascend Environment is distributed in hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     * General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with the program; if not, write to the Free Software Foundation,
20     * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
21     * COPYING.
22     */
23    
24     #include <stdio.h>
25 jds 60 #ifdef __WIN32__
26 jds 59 #include <io.h>
27 jds 60 #endif
28 jds 59 #include "utilities/ascConfig.h"
29     #include "utilities/ascMalloc.h"
30     #include "utilities/ascDynaLoad.h"
31     #include "CUnit/CUnit.h"
32     #include "test_ascDynaLoad.h"
33     #include "test_ascDynaLoad_shlib.h"
34    
35     /*
36     * ascDynaLoad.[ch] has several different platform-dependent
37     * implementations. This test function only tests the platform it
38     * is being run on. At present, testing is not implemented for all
39     * ASCEND platforms.
40     *
41     * This test function attempts to open and execute a shared library
42     * whose path is defined in variable shlib_name. Modify this variable
43     * for the shared library you want to use. Minimally, the shared
44     * library must provide the following public symbols:
45     *
46     * - init function, [int (*)(void)], returns -5.
47     * - isInitialized function, [int (*)(void)], returns TRUE if init()
48     * has been called, FALSE if cleanup or nothing has
49     * been called.
50     * - cleanup function, [void (*)(void)], no return.
51     * - value data [int] == FALSE initially, TRUE after init() has
52     * been called, FALSE after cleanup() has been called.
53     */
54     static void test_ascDynaLoad(void)
55     {
56     int open_success;
57     initFunc init_func;
58     isInitializedFunc isInitialized_func;
59     cleanupFunc cleanup_func;
60     valuetype *value;
61     unsigned long prior_meminuse;
62    
63 jds 60 #ifdef __WIN32__
64     const char *shlib_name = "..\\..\\..\\generic\\utilities\\test\\test_ascDynaLoad_shlib.dll";
65     #else
66     const char *shlib_name = "..\\..\\..\\generic\\utilities\\test\\test_ascDynaLoad_shlib.so";
67     #endif /* __WIN32__ */
68    
69    
70 jds 59 prior_meminuse = ascmeminuse(); /* save meminuse() at start of test function */
71    
72     /* test Asc_DynamicLoad(), Asc_DynamicUnLoad() */
73     CU_TEST(1 == Asc_DynamicLoad(NULL, NULL)); /* NULL path */
74     CU_TEST(-3 == Asc_DynamicUnLoad(NULL));
75    
76     CU_TEST(1 == Asc_DynamicLoad("dummy", NULL)); /* nonexistent shared lib */
77     CU_TEST(-3 == Asc_DynamicUnLoad("dummy"));
78    
79     if (0 == (open_success = Asc_DynamicLoad(shlib_name, NULL))) { /* shared lib with no init func */
80     CU_PASS("Opening of shared library succeeded.");
81    
82     CU_TEST(NULL != (init_func = (initFunc)Asc_DynamicSymbol(shlib_name, "init")));
83     CU_TEST(NULL != (isInitialized_func = (isInitializedFunc)Asc_DynamicSymbol(shlib_name, "isInitialized")));
84     CU_TEST(NULL != (cleanup_func = (cleanupFunc)Asc_DynamicSymbol(shlib_name, "cleanup")));
85     CU_TEST(NULL != (value = (valuetype*)Asc_DynamicSymbol(shlib_name, "value")));
86     if ((NULL == init_func) ||
87     (NULL == isInitialized_func) ||
88     (NULL == cleanup_func) ||
89     (NULL == value)) {
90     Asc_DynamicUnLoad(shlib_name);
91     return;
92     }
93    
94     CU_TEST(FALSE == (*isInitialized_func)());
95     CU_TEST(FALSE == (*value));
96     CU_TEST(-5 == (*init_func)());
97     CU_TEST(TRUE == (*isInitialized_func)());
98     CU_TEST(TRUE == (*value));
99     (*cleanup_func)();
100     CU_TEST(FALSE == (*isInitialized_func)());
101     CU_TEST(FALSE == (*value));
102    
103     CU_TEST(TRUE == Asc_DynamicUnLoad(shlib_name));
104     }
105     else {
106     CU_FAIL("Opening of shared library failed.");
107     }
108    
109     if (-5 == (open_success = Asc_DynamicLoad(shlib_name, "init"))) { /* shared lib with init func */
110     CU_PASS("Opening of shared library succeeded.");
111    
112     CU_TEST(NULL != (init_func = (initFunc)Asc_DynamicSymbol(shlib_name, "init")));
113     CU_TEST(NULL != (isInitialized_func = (isInitializedFunc)Asc_DynamicSymbol(shlib_name, "isInitialized")));
114     CU_TEST(NULL != (cleanup_func = (cleanupFunc)Asc_DynamicSymbol(shlib_name, "cleanup")));
115     CU_TEST(NULL != (value = (valuetype*)Asc_DynamicSymbol(shlib_name, "value")));
116     if ((NULL == init_func) ||
117     (NULL == isInitialized_func) ||
118     (NULL == cleanup_func) ||
119     (NULL == value)) {
120     Asc_DynamicUnLoad(shlib_name);
121     return;
122     }
123    
124     CU_TEST(TRUE == (*isInitialized_func)());
125     CU_TEST(TRUE == (*value));
126     (*cleanup_func)();
127     CU_TEST(FALSE == (*isInitialized_func)());
128     CU_TEST(FALSE == (*value));
129    
130     CU_TEST(TRUE == Asc_DynamicUnLoad(shlib_name));
131     }
132     else {
133     CU_FAIL("Opening of shared library failed.");
134     }
135    
136     /* test Asc_DynamicSymbol() - normal operation tested in previous tests */
137    
138     CU_TEST(NULL == Asc_DynamicSymbol(NULL, "init")); /* NULL libname */
139     CU_TEST(NULL == Asc_DynamicSymbol(shlib_name, NULL)); /* NULL symbol */
140     CU_TEST(NULL == Asc_DynamicSymbol(shlib_name, "init")); /* library not open */
141    
142     CU_TEST(prior_meminuse == ascmeminuse()); /* make sure we cleaned up after ourselves */
143     }
144    
145     /*===========================================================================*/
146     /* Registration information */
147    
148     static CU_TestInfo ascDynaLoad_test_list[] = {
149     {"test_ascDynaLoad", test_ascDynaLoad},
150     CU_TEST_INFO_NULL
151     };
152    
153     static CU_SuiteInfo suites[] = {
154     {"test_utilities_ascDynaLoad", NULL, NULL, ascDynaLoad_test_list},
155     CU_SUITE_INFO_NULL
156     };
157    
158     /*-------------------------------------------------------------------*/
159     CU_ErrorCode test_register_utilities_ascDynaLoad(void)
160     {
161     return CU_register_suites(suites);
162     }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22