X-Git-Url: https://git.saurik.com/apple/mdnsresponder.git/blobdiff_plain/8e92c31c9a45a66732f5bc7afbc9f5596c17e91d..aed41e04134477b192c038aeb16b17c47b959fc7:/Clients/Java/DNSSDUnitTest.java diff --git a/Clients/Java/DNSSDUnitTest.java b/Clients/Java/DNSSDUnitTest.java index e4523e1..2b1839a 100644 --- a/Clients/Java/DNSSDUnitTest.java +++ b/Clients/Java/DNSSDUnitTest.java @@ -1,40 +1,20 @@ -/* +/* -*- Mode: Java; tab-width: 4 -*- + * * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 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. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - - Change History (most recent first): - -$Log: DNSSDUnitTest.java,v $ -Revision 1.3 2004/05/26 01:41:58 cheshire -Pass proper flags to DNSSD.enumerateDomains - -Revision 1.2 2004/04/30 21:53:34 rpantos -Change line endings for CVS. - -Revision 1.1 2004/04/30 16:29:35 rpantos -First checked in. - - DNSSDUnitTest is a simple program that exercises parts of the DNSSD API. + * + * DNSSDUnitTest is a simple program that exercises parts of the DNSSD API. */ import com.apple.dnssd.*; @@ -67,19 +47,34 @@ class DNSSDUnitTest String a; txtRecord.set( "path", "~/names"); + txtRecord.set( "rw", (String) null); + txtRecord.set( "empty", ""); txtRecord.set( "ttl", "4"); byte[] rawBytes = txtRecord.getRawBytes(); System.out.println( ( new String( rawBytes, 0, rawBytes.length)) + " has count " + String.valueOf( txtRecord.size())); + System.out.println( txtRecord); boolean ttlPresent = txtRecord.contains( "ttl"); System.out.println( "ttl is present: " + ( ttlPresent ? "true" : "false")); boolean timeoutPresent = txtRecord.contains( "timeout"); System.out.println( "timeout is present: " + ( timeoutPresent ? "true" : "false")); - for ( int i=0; null != ( a = txtRecord.getKey( i)); i++) - System.out.println( "attr/val " + String.valueOf( i) + ": " + a + "," + txtRecord.getValueAsString( i)); + txtRecord.set( "path", "~/numbers"); + System.out.println( txtRecord); + + txtRecord.remove( "ttl"); + System.out.println( txtRecord); + + txtRecord.remove( "path"); + System.out.println( txtRecord); + + txtRecord.remove( "at"); + System.out.println( txtRecord); + + txtRecord.set( "rw", "1"); + System.out.println( txtRecord); } public void run() throws DNSSDException @@ -91,6 +86,7 @@ class DNSSDUnitTest fRegTest = new RegTest(); new BrowseTest(); new DomainTest(); + new RegistrarTest(); this.waitForEnd(); } @@ -309,3 +305,30 @@ class QueryTest extends TermReporter implements QueryListener } } +class RegistrarTest extends TermReporter implements RegisterRecordListener +{ + public RegistrarTest() + { + try { + byte[] kResponsiblePerson = { 'g','r','o','v','e','r' }; + fRegistrar = DNSSD.createRecordRegistrar( this); + fRegistrar.registerRecord( DNSSD.UNIQUE, 0, + "test.registrartest.local", 17 /*ns_t_rp*/, 1, kResponsiblePerson, 3600); + } catch( Exception e) { e.printStackTrace(); } + } + + public void recordRegistered( DNSRecord record, int flags) + { + String s = "RegistrarTest result flags:" + String.valueOf( flags); + System.out.println( s); + + try { + byte[] kResponsiblePerson = { 'e','l','m','o' }; + record.update( 0, kResponsiblePerson, 3600); + record.remove(); + } catch( Exception e) { e.printStackTrace(); } + } + + protected DNSSDRecordRegistrar fRegistrar; +} +