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