Annotation of XNU/libkern/c++/Tests/TestSerialization/test2.kmodproj/test2_main.cpp, revision 1.1

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 test2_start;
        !            30: kmod_stop_func_t test2_stop;
        !            31: __END_DECLS
        !            32: 
        !            33: #include <libkern/c++/OSContainers.h>
        !            34: #include <iokit/IOLib.h>
        !            35: 
        !            36: char *testBuffer = "
        !            37:  <?xml version=\"1.0\" encoding=\"UTF-8\"?>
        !            38:  <!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">
        !            39:  <plist version=\"0.9\">
        !            40:  <dict>
        !            41: 
        !            42:  <key>key true</key>   <true/>
        !            43:  <key>key false</key>  <false/>
        !            44: 
        !            45:  <key>key d0</key>     <data> </data>
        !            46:  <key>key d1</key>     <data>AQ==</data>
        !            47:  <key>key d2</key>     <data>ASM=</data>
        !            48:  <key>key d3</key>     <data>ASNF</data>
        !            49:  <key>key d4</key>     <data ID=\"1\">ASNFZw==</data>
        !            50: 
        !            51:  <key>key i0</key>     <integer></integer>
        !            52:  <key>key i1</key>     <integer>123456789</integer>
        !            53:  <key>key i2</key>     <integer size=\"32\" ID=\"2\">0x12345678</integer>
        !            54: 
        !            55:  <key>key s0</key>     <string></string>
        !            56:  <key>key s1</key>     <string>string 1</string>
        !            57:  <key>key s2</key>     <string ID=\"3\">string 2</string>
        !            58:  <key>key &lt;&amp;&gt;</key>  <string>&lt;&amp;&gt;</string>
        !            59: 
        !            60:  <key>key c0</key>     <dict ID=\"4\">
        !            61:                         </dict>
        !            62: 
        !            63:  <key>key a0</key>     <array>
        !            64:                         </array>
        !            65: 
        !            66:  <key>key a1</key>     <array ID=\"5\">
        !            67:                             <string>array string 1</string>
        !            68:                             <string>array string 2</string>
        !            69:                         </array>
        !            70: 
        !            71:  <key>key t0</key>     <set>
        !            72:                         </set>
        !            73:  <key>key t1</key>     <set ID=\"6\">
        !            74:                              <string>set string 1</string>
        !            75:                              <string>set string 2</string>
        !            76:                          </set>
        !            77: 
        !            78:  <key>key r1</key>     <ref IDREF=\"1\"/>
        !            79:  <key>key r2</key>     <ref IDREF=\"2\"/>
        !            80:  <key>key r2</key>     <ref IDREF=\"3\"/>
        !            81:  <key>key r2</key>     <ref IDREF=\"4\"/>
        !            82:  <key>key r2</key>     <ref IDREF=\"5\"/>
        !            83:  <key>key r2</key>     <ref IDREF=\"6\"/>
        !            84: 
        !            85:  </dict>
        !            86:  </plist>
        !            87: ";
        !            88: 
        !            89: /*
        !            90:  this causes the parser to return an empty string? it doesn't look like yyerror gets called
        !            91:  char *testBuffer = "<array ID=1><array IDREF=\"1\"/></array>"
        !            92:  
        !            93: */
        !            94: 
        !            95: kern_return_t
        !            96: test2_start(struct kmod_info *ki, void *data)
        !            97: {
        !            98:         IOLog("test buffer start:\n%s\n:test buffer end.\n", testBuffer);
        !            99: 
        !           100:        // test unserialize
        !           101:        OSString *errmsg = 0;
        !           102:        OSObject *d = OSUnserializeXML(testBuffer, &errmsg);
        !           103:        if (!d) {
        !           104:                 if (errmsg)
        !           105:                     IOLog("%s\n", errmsg->getCStringNoCopy());
        !           106:                 else
        !           107:                     IOLog("bogus error message\n");
        !           108:             
        !           109:                return KMOD_RETURN_SUCCESS;
        !           110:        }
        !           111:         
        !           112:        // test serialize
        !           113:        OSSerialize *s = OSSerialize::withCapacity(5);
        !           114:        if (!d->serialize(s)) {
        !           115:                IOLog("serialization failed\n");
        !           116:                 return KMOD_RETURN_SUCCESS;
        !           117:        }
        !           118: 
        !           119:        IOLog("serialized object's length = %d, capacity = %d\n", s->getLength(), s->getCapacity());
        !           120:        IOLog("object unformatted = %s\n", s->text());
        !           121: 
        !           122:        // try second time
        !           123:        OSObject *d2 = OSUnserializeXML(s->text(), &errmsg);
        !           124:        if (!d2) {
        !           125:                IOLog("%s\n", errmsg->getCStringNoCopy());
        !           126:                 return KMOD_RETURN_SUCCESS;
        !           127:        }
        !           128:        OSSerialize *s2 = OSSerialize::withCapacity(5);
        !           129:        if (!d2->serialize(s2)) {
        !           130:                IOLog("serialization #2 failed\n");
        !           131:                 return KMOD_RETURN_SUCCESS;
        !           132:        }
        !           133: 
        !           134:        IOLog("serialized object's length = %d, capacity = %d\n", 
        !           135:                s2->getLength(), s2->getCapacity());
        !           136:        IOLog("object unformatted = %s\n", s2->text());
        !           137: 
        !           138:        IOLog("\nserialized objects compared %ssuccessfully textually\n\n",
        !           139:               strcmp(s->text(), s2->text()) ? "un":""); 
        !           140: 
        !           141:        IOLog("\nserialized objects compared %ssuccessfully objectwise\n\n",
        !           142:               d->isEqualTo(d2) ? "":"un"); 
        !           143: 
        !           144:        s2->release();
        !           145:        if (d2) d2->release();
        !           146:        s->release();
        !           147:        if (d) d->release();
        !           148: 
        !           149:         return KMOD_RETURN_SUCCESS;
        !           150: }
        !           151: 
        !           152: kern_return_t
        !           153: test2_stop(struct kmod_info *ki, void *data)
        !           154: {
        !           155:         return KMOD_RETURN_SUCCESS;
        !           156: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.