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