1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 /*
5  * test_resourcelimits.c
6  *
7  * Test ResourceLimits Type
8  *
9  */
10 
11 #include "testutil.h"
12 #include "testutil_nss.h"
13 
14 static void *plContext = NULL;
15 
16 static void
testDestroy(void * goodObject,void * equalObject,void * diffObject)17 testDestroy(void *goodObject, void *equalObject, void *diffObject)
18 {
19     PKIX_TEST_STD_VARS();
20 
21     subTest("PKIX_ResourceLimits_Destroy");
22 
23     PKIX_TEST_DECREF_BC(goodObject);
24     PKIX_TEST_DECREF_BC(equalObject);
25     PKIX_TEST_DECREF_BC(diffObject);
26 
27 cleanup:
28 
29     PKIX_TEST_RETURN();
30 }
31 
32 int
test_resourcelimits(int argc,char * argv[])33 test_resourcelimits(int argc, char *argv[])
34 {
35 
36     PKIX_ResourceLimits *goodObject = NULL;
37     PKIX_ResourceLimits *equalObject = NULL;
38     PKIX_ResourceLimits *diffObject = NULL;
39     PKIX_UInt32 maxTime = 0;
40     PKIX_UInt32 maxFanout = 0;
41     PKIX_UInt32 maxDepth = 0;
42     PKIX_UInt32 actualMinorVersion;
43     PKIX_UInt32 j = 0;
44     char *expectedAscii =
45         "[\n"
46         "\tMaxTime:           		10\n"
47         "\tMaxFanout:         		5\n"
48         "\tMaxDepth:         		5\n"
49         "]\n";
50 
51     PKIX_TEST_STD_VARS();
52 
53     startTests("ResourceLimits");
54 
55     PKIX_TEST_EXPECT_NO_ERROR(
56         PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
57 
58     subTest("PKIX_ResourceLimits_Create");
59     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_Create(&goodObject, plContext));
60     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_Create(&diffObject, plContext));
61     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_Create(&equalObject, plContext));
62 
63     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxTime(goodObject, 10, plContext));
64     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_GetMaxTime(goodObject, &maxTime, plContext));
65     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxTime(equalObject, maxTime, plContext));
66     maxTime++;
67     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxTime(diffObject, maxTime, plContext));
68 
69     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxFanout(goodObject, 5, plContext));
70     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_GetMaxFanout(goodObject, &maxFanout, plContext));
71     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxFanout(equalObject, maxFanout, plContext));
72     maxFanout++;
73     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxFanout(diffObject, maxFanout, plContext));
74 
75     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxDepth(goodObject, 5, plContext));
76     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_GetMaxDepth(goodObject, &maxDepth, plContext));
77     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxDepth(equalObject, maxDepth, plContext));
78     maxDepth++;
79     PKIX_TEST_EXPECT_NO_ERROR(PKIX_ResourceLimits_SetMaxDepth(diffObject, maxDepth, plContext));
80 
81     PKIX_TEST_EQ_HASH_TOSTR_DUP(goodObject,
82                                 equalObject,
83                                 diffObject,
84                                 expectedAscii,
85                                 ResourceLimits,
86                                 PKIX_FALSE);
87 
88     testDestroy(goodObject, equalObject, diffObject);
89 
90 cleanup:
91 
92     PKIX_Shutdown(plContext);
93 
94     PKIX_TEST_RETURN();
95 
96     endTests("ResourceLimits");
97 
98     return (0);
99 }
100