1*c54f35caSApple OSS Distributions /*
2*c54f35caSApple OSS Distributions * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3*c54f35caSApple OSS Distributions *
4*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*c54f35caSApple OSS Distributions *
6*c54f35caSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*c54f35caSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*c54f35caSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*c54f35caSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*c54f35caSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*c54f35caSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*c54f35caSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*c54f35caSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*c54f35caSApple OSS Distributions *
15*c54f35caSApple OSS Distributions * Please obtain a copy of the License at
16*c54f35caSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*c54f35caSApple OSS Distributions *
18*c54f35caSApple OSS Distributions * The Original Code and all software distributed under the License are
19*c54f35caSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*c54f35caSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*c54f35caSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*c54f35caSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*c54f35caSApple OSS Distributions * Please see the License for the specific language governing rights and
24*c54f35caSApple OSS Distributions * limitations under the License.
25*c54f35caSApple OSS Distributions *
26*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*c54f35caSApple OSS Distributions */
28*c54f35caSApple OSS Distributions #include <libkern/OSBase.h>
29*c54f35caSApple OSS Distributions
30*c54f35caSApple OSS Distributions __BEGIN_DECLS
31*c54f35caSApple OSS Distributions #include <mach/mach_types.h>
32*c54f35caSApple OSS Distributions #include <mach/vm_types.h>
33*c54f35caSApple OSS Distributions #include <mach/kmod.h>
34*c54f35caSApple OSS Distributions
35*c54f35caSApple OSS Distributions kmod_start_func_t test1_start;
36*c54f35caSApple OSS Distributions kmod_stop_func_t test1_stop;
37*c54f35caSApple OSS Distributions __END_DECLS
38*c54f35caSApple OSS Distributions
39*c54f35caSApple OSS Distributions #include <libkern/c++/OSContainers.h>
40*c54f35caSApple OSS Distributions #include <iokit/IOLib.h>
41*c54f35caSApple OSS Distributions
42*c54f35caSApple OSS Distributions const char *testBuffer = ""
43*c54f35caSApple OSS Distributions "{ string = \"this is a 'string' with spaces\";"
44*c54f35caSApple OSS Distributions " string2 = 'this is also a \"string\" with spaces';"
45*c54f35caSApple OSS Distributions " offset = 16384:32;"
46*c54f35caSApple OSS Distributions " true = .true.;"
47*c54f35caSApple OSS Distributions " false = .false.;"
48*c54f35caSApple OSS Distributions " data = <0123 4567 89abcdef>;"
49*c54f35caSApple OSS Distributions " array = (1:8, 2:16, 3:32, 4:64 );"
50*c54f35caSApple OSS Distributions " set = [ one, two, three, four ];"
51*c54f35caSApple OSS Distributions " emptydict = { }@1;"
52*c54f35caSApple OSS Distributions " emptyarray = ( )@2;"
53*c54f35caSApple OSS Distributions " emptyset = [ ]@3;"
54*c54f35caSApple OSS Distributions " emptydata = < >@4;"
55*c54f35caSApple OSS Distributions " emptydict2 = @1;"
56*c54f35caSApple OSS Distributions " emptyarray2 = @2;"
57*c54f35caSApple OSS Distributions " emptyset2 = @3;"
58*c54f35caSApple OSS Distributions " emptydata2 = @4;"
59*c54f35caSApple OSS Distributions " dict2 = { string = asdfasdf; };"
60*c54f35caSApple OSS Distributions " dict3 = { string = asdfasdf; };"
61*c54f35caSApple OSS Distributions "}@0";
62*c54f35caSApple OSS Distributions
63*c54f35caSApple OSS Distributions kern_return_t
test1_start(struct kmod_info * ki,void * data)64*c54f35caSApple OSS Distributions test1_start(struct kmod_info *ki, void *data)
65*c54f35caSApple OSS Distributions {
66*c54f35caSApple OSS Distributions IOLog("test buffer start:\n%s\n:test buffer end.\n", testBuffer);
67*c54f35caSApple OSS Distributions
68*c54f35caSApple OSS Distributions // test unserialize
69*c54f35caSApple OSS Distributions OSString *errmsg;
70*c54f35caSApple OSS Distributions OSObject *d = OSUnserialize(testBuffer, &errmsg);
71*c54f35caSApple OSS Distributions if (!d) {
72*c54f35caSApple OSS Distributions IOLog("%s\n", errmsg->getCStringNoCopy());
73*c54f35caSApple OSS Distributions return KMOD_RETURN_SUCCESS;
74*c54f35caSApple OSS Distributions }
75*c54f35caSApple OSS Distributions
76*c54f35caSApple OSS Distributions // test serialize
77*c54f35caSApple OSS Distributions OSSerialize *s = OSSerialize::withCapacity(5);
78*c54f35caSApple OSS Distributions if (!d->serialize(s)) {
79*c54f35caSApple OSS Distributions IOLog("serialization failed\n");
80*c54f35caSApple OSS Distributions return KMOD_RETURN_SUCCESS;
81*c54f35caSApple OSS Distributions }
82*c54f35caSApple OSS Distributions
83*c54f35caSApple OSS Distributions IOLog("serialized object's length = %d, capacity = %d\n", s->getLength(), s->getCapacity());
84*c54f35caSApple OSS Distributions IOLog("object unformatted = %s\n", s->text());
85*c54f35caSApple OSS Distributions
86*c54f35caSApple OSS Distributions // try second time
87*c54f35caSApple OSS Distributions OSObject *d2 = OSUnserializeXML(s->text(), &errmsg);
88*c54f35caSApple OSS Distributions if (!d2) {
89*c54f35caSApple OSS Distributions IOLog("%s\n", errmsg->getCStringNoCopy());
90*c54f35caSApple OSS Distributions return KMOD_RETURN_SUCCESS;
91*c54f35caSApple OSS Distributions }
92*c54f35caSApple OSS Distributions
93*c54f35caSApple OSS Distributions IOLog("\nserialized objects compared %ssuccessfully objectwise\n\n",
94*c54f35caSApple OSS Distributions d->isEqualTo(d2) ? "":"un");
95*c54f35caSApple OSS Distributions
96*c54f35caSApple OSS Distributions if (d2) {
97*c54f35caSApple OSS Distributions d2->release();
98*c54f35caSApple OSS Distributions }
99*c54f35caSApple OSS Distributions s->release();
100*c54f35caSApple OSS Distributions if (d) {
101*c54f35caSApple OSS Distributions d->release();
102*c54f35caSApple OSS Distributions }
103*c54f35caSApple OSS Distributions
104*c54f35caSApple OSS Distributions return KMOD_RETURN_SUCCESS;
105*c54f35caSApple OSS Distributions }
106*c54f35caSApple OSS Distributions
107*c54f35caSApple OSS Distributions kern_return_t
test1_stop(struct kmod_info * ki,void * data)108*c54f35caSApple OSS Distributions test1_stop(struct kmod_info *ki, void *data)
109*c54f35caSApple OSS Distributions {
110*c54f35caSApple OSS Distributions return KMOD_RETURN_SUCCESS;
111*c54f35caSApple OSS Distributions }
112