~verterok/ubuntu/lucid/protobuf/2.4.0a-backport

« back to all changes in this revision

Viewing changes to java/src/test/java/com/google/protobuf/AbstractMessageTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
366
366
 
367
367
  // -----------------------------------------------------------------
368
368
  // Tests for equals and hashCode
369
 
  
 
369
 
370
370
  public void testEqualsAndHashCode() throws Exception {
371
371
    TestAllTypes a = TestUtil.getAllSet();
372
372
    TestAllTypes b = TestAllTypes.newBuilder().build();
382
382
    checkEqualsIsConsistent(d);
383
383
    checkEqualsIsConsistent(e);
384
384
    checkEqualsIsConsistent(f);
385
 
    
 
385
 
386
386
    checkNotEqual(a, b);
387
387
    checkNotEqual(a, c);
388
388
    checkNotEqual(a, d);
413
413
    checkEqualsIsConsistent(eUnknownFields);
414
414
    checkEqualsIsConsistent(fUnknownFields);
415
415
 
416
 
    // Subseqent reconstitutions should be identical
 
416
    // Subsequent reconstitutions should be identical
417
417
    UnittestProto.TestEmptyMessage eUnknownFields2 =
418
418
        UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray());
419
419
    checkEqualsIsConsistent(eUnknownFields, eUnknownFields2);
420
420
  }
421
 
  
 
421
 
 
422
 
422
423
  /**
423
424
   * Asserts that the given proto has symetric equals and hashCode methods.
424
425
   */
425
426
  private void checkEqualsIsConsistent(Message message) {
426
427
    // Object should be equal to itself.
427
428
    assertEquals(message, message);
428
 
    
 
429
 
429
430
    // Object should be equal to a dynamic copy of itself.
430
431
    DynamicMessage dynamic = DynamicMessage.newBuilder(message).build();
431
432
    checkEqualsIsConsistent(message, dynamic);
442
443
 
443
444
  /**
444
445
   * Asserts that the given protos are not equal and have different hash codes.
445
 
   * 
 
446
   *
446
447
   * @warning It's valid for non-equal objects to have the same hash code, so
447
448
   *   this test is stricter than it needs to be. However, this should happen
448
449
   *   relatively rarely.