/* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This 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 OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_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 char *testBuffer = " key true key false key d0 key d1 AQ== key d2 ASM= key d3 ASNF key d4 0123 4567 89abcdef key d5 ASNFZw== key i0 key i1 123456789 key i2 0x12345678 key s0 key s1 string 1 key s2 string 2 key <&> <&> key c0 key a0 key a1 array string 1 array string 2 key t0 key t1 set string 1 set string 2 key r1 key r2 key r3 key r4 key r5 key r6 key e1 key e2 key e3 key e4 key e5 key e6 "; /* 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; }