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