/* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #include __BEGIN_DECLS #include #include #include kmod_start_func_t test2_start; kmod_stop_func_t test2_stop; __END_DECLS #include #include const char *testBuffer = " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " key true \n" " key false \n" " key d0 \n" " key d1 AQ== \n" " key d2 ASM= \n" " key d3 ASNF \n" " key d4 ASNFZw== \n" " key i0 \n" " key i1 123456789 \n" " key i2 -123456789 \n" " key i3 0x12345678 \n" " key s0 \n" " key s1 string 1 \n" " key s2 string 2 \n" " key mr � mac roman copyright � \n" " key uft8 \xc2\xa9 utf-8 copyright \xc2\xa9 \n" " key <&> <&> \n" " key D0 \n" " \n" " key a0 \n" " \n" " key a1 \n" " array string 1 \n" " array string 2 \n" " \n" " key r1 \n" " key r2 \n" " key r3 \n" " key r4 \n" " key r5 \n" " key e1 \n" " key e2 \n" " key e4 \n" " key e5 \n" " key e6 \n" " key S0 \n" " \n" " key S1 \n" " set string 1 \n" " set string 2 \n" " \n" " key r6 \n" " key e3 \n" " \n" " \n" ; /* this causes the parser to return an empty string? it doesn't look like yyerror gets called char *testBuffer = "" */ kern_return_t test2_start(struct kmod_info *ki, void *data) { IOLog("test buffer start:\n%s\n:test buffer end.\n", testBuffer); // test unserialize OSString *errmsg = 0; OSObject *d = OSUnserializeXML(testBuffer, &errmsg); if (!d) { if (errmsg) IOLog("%s\n", errmsg->getCStringNoCopy()); else IOLog("bogus error message\n"); return KMOD_RETURN_SUCCESS; } // test serialize OSSerialize *s = OSSerialize::withCapacity(5); if (!d->serialize(s)) { IOLog("serialization failed\n"); return KMOD_RETURN_SUCCESS; } IOLog("serialized object's length = %d, capacity = %d\n", s->getLength(), s->getCapacity()); IOLog("object unformatted = %s\n", s->text()); // try second time OSObject *d2 = OSUnserializeXML(s->text(), &errmsg); if (!d2) { IOLog("%s\n", errmsg->getCStringNoCopy()); return KMOD_RETURN_SUCCESS; } OSSerialize *s2 = OSSerialize::withCapacity(5); if (!d2->serialize(s2)) { IOLog("serialization #2 failed\n"); return KMOD_RETURN_SUCCESS; } IOLog("serialized object's length = %d, capacity = %d\n", s2->getLength(), s2->getCapacity()); IOLog("object unformatted = %s\n", s2->text()); IOLog("\nserialized objects compared %ssuccessfully textually\n\n", strcmp(s->text(), s2->text()) ? "un":""); IOLog("\nserialized objects compared %ssuccessfully objectwise\n\n", d->isEqualTo(d2) ? "":"un"); s2->release(); if (d2) d2->release(); s->release(); if (d) d->release(); return KMOD_RETURN_SUCCESS; } kern_return_t test2_stop(struct kmod_info *ki, void *data) { return KMOD_RETURN_SUCCESS; }