History log of /libcore/luni/src/test/java/libcore/java/util/TreeMapTest.java
Revision Date Author Comments
b19d698cc2638b55d67f076585771bc959b0844f 17-Aug-2016 Tobias Thierer <tobiast@google.com> Revert "Workaround bogus TreeMap Comparators."

This was a temporary workaround for app compatibility in Android N and O.

Bug: 27913360
Test: CtsLibcoreTestCases

This reverts commit 78562a12977fc4d81cd31e7c5af05d66bb701ccd.

Change-Id: I3a2377ed4dc4da846828ee4b08b3037fc3045fe5
(cherry picked from commit 52c8fbf265cfac2022cee75068509ac2538eda71)
52c8fbf265cfac2022cee75068509ac2538eda71 17-Aug-2016 Tobias Thierer <tobiast@google.com> Revert "Workaround bogus TreeMap Comparators."

This was a temporary workaround for app compatibility in Android N and O.

Bug: 27913360
Test: CtsLibcoreTestCases

This reverts commit 78562a12977fc4d81cd31e7c5af05d66bb701ccd.

Change-Id: I3a2377ed4dc4da846828ee4b08b3037fc3045fe5
d430cc782689a7f6a256ef6b0ebfc7210b0c31d9 01-Nov-2017 Tobias Thierer <tobiast@google.com> Move libcore tests to non-libcore packages.

The integration of OpenJDK 9 javac into the Android build system
requires non-libcore code to live in non-libcore packages, as
long as that code isn't considered part of the same module as
libcore at javac time.

This CL moves libcore test related classes out of such
packages; since libcore tests could already only test
public (as opposed to package private APIs), no change
other than the package name and imports is necessary.

Because many libcore tests already live below a top-level
package "libcore" (eg., the tests for java.util are in
libcore.java.util), this CL likewise prepends "libcore."
to the package names of affected classes. For classes
relating to libcore.* packages, this results in a package
name of the form "libcore.libcore.*".

Alternative considered but not pursued:
To compile the test classes without moving the out of a libcore
package, javac would need to consider them to be in the same
module as libcore. This would likely be possible via
javac --patch-module, but this has not been explored in detail
because:

- Most luni tests are already in a toplevel package libcore.*,
so this CL makes the test structure more consistent.
- Use of --patch-module would likely cause problems when running
tests under a runtime that implements the OpenJDK 9 module
system; for example, --patch-module cannot add exported
packages to the module, so any new packages added in tests
(such as the libcore.* packages of most existing luni tests)
would not be visible at test runtime.
- Having tests in different packages from code under tests makes
it more obvious (including to IDEs in which the code might be
edited as a single project) that these tests cannot access
package-private identifiers in the code under test.

Test: Treehugger
Test: "make cts" with EXPERIMENTAL_USE_OPENJDK9=true
passes with additional changes present locally
that have not yet been exported as CLs.
Test: CtsLibcoreTestCases
Bug: 68224249
Bug: 68932217 (tracks potential follow-up work)

Change-Id: Ib6b8e6f3bc87093bc219d2108e601163c6e334cd
5665b19f6012807c7765aa860baa6b01bbcd1c67 03-Feb-2017 Tobias Thierer <tobiast@google.com> Improve TreeMapTest

The test was constructing lists of expected keys/values/entries
on top of TreeMap's collection view iterators. These tests might
have missed bugs where the Iterator order was consistent but
wrong. This CL changes the test to explicitly specify the
expected order of elements.

In addition, the order of put() commands populating TreeMap
instances for testing matched the expected iteration order;
this would have missed bugs where TreeMap's iteration order
was based on insertion rather than Comparator order.
This CL changes the order of the put() calls to cover this
behavior aspect.

SpliteratorTester's method signatures were also relaxed to
not rely on particular List implementations for expected
values.

Test: TreeMapTest

Change-Id: Ia649c81cc73d6e66165397f97188ab21ac0f3933
508f0abe4f8686d29466b2c364cb4f60bf0484b5 16-Jan-2017 Tobias Thierer <tobiast@google.com> Basic tests for wrapper Collection factories in java.util.Collections

Basic test coverage for the wrapper Collections constructed by
the following static factory methods in java.util.Collections:

checkedNavigableMap()
checkedNavigableSet()
checkedQueue()
emptyNavigableMap()
emptyNavigableSet()
emptySortedMap()
emptySortedSet()
synchronizedNavigableMap()
synchronizedNavigableSet()
unmodifiableNavigableMap()
unmodifiableNavigableSet()

These 11 methods under test are the only ones currently annotated
@hide in Collections.java; this CL provides sufficient test coverage
for those to be un-hidden in a follow-up CL.

Most (perhaps all) aspects covered by these tests are also covered
by guava-testlib-21.0 tests, but those are not yet available in
AOSP and would take 80min to run, whereas these new tests only take
a few seconds to run.

SpliteratorTester previously contained some overly strict assertions
that Spliterator.trySplit() != null. This CL relaxes this assumption
for non-empty spliterables but adds a separate assertSupportsTrySplit()
check in the places that previously exercised this strict test logic;
Where the old tests appeared to be testing the wrong collection (e.g.
in HashSetTest), this CL asserts the support for trySplit on what
appears to be the correct Collection, but does not otherwise fix the
existing test code.

Bug: 29935305
Test: CtsLibcoreTestCases
Change-Id: Ibeac242bb60df7b06a1c8c80dc744707f734d91c
48b8a257f78d6def94079b592000f9f5ff17fb3c 05-Jan-2017 Tobias Thierer <tobiast@google.com> Revert "Revert "Workaround bogus TreeMap Comparators.""

An app that is popular among testers is still broken.
This CL re-establishes the work-around to give the
app a little bit of time to update their dependencies
to the fixed versions.

This reverts commit 3733bc930b4f8a02b278dde1109d0cd42f7c4c08.

By reverting that revert, this CL re-applies the changes from
commit 78562a12977fc4d81cd31e7c5af05d66bb701ccd

*** THIS CHANGE IS TEMPORARY AND WILL LIKELY BE ***
*** REVERTED BEFORE THE NEXT ANDROID RELEASE ***

Test: cts-tradefed run cts -m CtsLibcoreTestCases -a arm64-v8a
Test: these tests from guava-testlib 21.0-rc2's TestsForMapsInJavaUtil:
- testsForTreeMapNatural()
- testsForTreeMapWithComparator()

Bug: 34084348

Change-Id: I3d120f00bf5a14e89cf3d50c3931557191aa5f37
b7614d4830d62ea3980797669e69ade24ac0d98c 16-Aug-2016 Tobias Thierer <tobiast@google.com> Update TreeMap to OpenJDK8u60.

All existing local changes were kept:

* toplevel documentation link via openjdk-redirect.html

* naming of nested class TreeMapEntry
- added a test
- added an Android-changed comment block

* value of NavigableSubMap.serialVersionUID

* range checks for tailMap() / headMap()
- changed "BEGIN android" comment format to the more common
(640 vs. 69 occurences) format "Android-changed BEGIN".
- these are covered by the tests added in AOSP commit
26b39cc71ae9c0890b1c56f7062debd4b555811c

Existing tests in HashtableTest and LinkedHashMapTest differed
slightly from the new tests in TreeMapTest, so they were tweaked
to make them consistent.

Test: cts-tradefed run cts -p android.core.tests.libcore.package.libcore
Test: Guava 19.0 guava-testlib's testForTreeMapNatural() and
testsForTreeMapWithComparator() (96850 test methods run).

Bug: 29935305

Change-Id: Ia5064afa38c64b8ca0d08a91d1766958da58d6e6
26b39cc71ae9c0890b1c56f7062debd4b555811c 17-Aug-2016 Tobias Thierer <tobiast@google.com> Comprehensive tests for bounds check in TreeMap's submaps.

AOSP commit b4105e7f1e3ab24131976f68be4554e694a0e1d4 established
bounds checking behavior for TreeMap.{tail,head}map() in Android N
that matches the behavior in earlier versions of Android. This
behavior is covered by the existing comprehensive TreeMapExtendTest
but that test is hard to follow since it's over 13k lines long
and somewhat convoluted (no comments). This makes it hard to verify
whether a particular case is covered by the test or understand why
a test may be failing.

This CL adds comprehensive, documented tests for all 16 possible
combinations of an (inclusive, exclusive) (head, tail) map being
constructed from a parent (head, tail) map with (inclusive,
exclusive) bound.

These tests ensure that any future changes in Android's behavior
in this regard will not be accidental and that a potential
failure can be analysed efficiently.

Since the exact value of the bound doesn't matter, the test
here always uses an (inclusive or exclusive) bound of 0 with
a TreeMap<Integer, Void>.

Test: cts-tradefed run cts -c libcore.java.util.TreeMapTest

Change-Id: Iadebbb44342929820c242d922b8561f05ddb5fb8
3733bc930b4f8a02b278dde1109d0cd42f7c4c08 17-Aug-2016 Tobias Thierer <tobiast@google.com> Revert "Workaround bogus TreeMap Comparators."

This was a temporary workaround for app compatibility in Android N.

Bug: 27913360
Test: cts-tradefed run cts -p android.core.tests.libcore.package.libcore

This reverts commit 78562a12977fc4d81cd31e7c5af05d66bb701ccd.

Change-Id: Ib03ee04d17da5d2b8e943c2da9b7351f852ce716
9efb6d12ce4d2ffedb73d6e9887ea2c89f8ec129 08-Jun-2016 Narayan Kamath <narayan@google.com> Update HashMap, HashSet, LinkedHashMap to JDK8u60.

Added tests for:
- entrySet()/keySet()/values() spliterators (LinkedHashMap
has completely new implementations)
- LinkedHashMap.eldest (Android specific API, previously
existed but was untested)
- naming of nested class LinkedHashMap.LinkedHashMapEntry
- tweaked test for Map.getOrDefault() method so it's useful
for LinkedHashMap

This CL doesn't touch HashSetTest since it already covered
spliterator() and serialization.

Test: Ran all libcore tests.

Bug: 29935305
Change-Id: I9d991a08c403b83b15e9c88ce97cbd5cd77a8bcf
1f01b0e27882d669217e3acf9d429ea9afbac47e 20-Apr-2016 Shubham Ajmera <shubhamajmera@google.com> Add missed overrides for OpenJDK 8 Map default methods

Both the replace methods in TreeMap were left intentionally in the
commit 0e83756c4295f4df3853047205d94fe845573522 as there were no
behavioral differences and the default implementation was considered
sufficient. However, the upstream version is more efficient so that is
being added here.

As of now, all the overrides for the Map default implementation have
been put from the upstream, except for Hashtable and HashMap. Both
of these classes are quite different from their OpenJDK 8 versions to
accommodate the overrides. HashMap depends on the default implementation
for the following methods:

#getOrDefault
#replace(K, V)
#computeIfAbsent
#computeIfPresent
#compute
#merge

#replace(K, V, V) was reimplemented due to the behavioral differences
with the default implementation.

The following Hashtable methods are also dependent on the map default
implementation, though, they have added synchronization.

#getOrDefault
#putIfAbsent
#remove
#replace(K, V, V)
#replace(K, V)
#computeIfAbsent
#computeIfPresent
#compute

Once the classes get ready with the new changes comes with OpenJDK 8,
the above methods would be put in.

Bug: 27426743
Change-Id: Iee4fb156eddee17187386bbfffc8517415030a94
(cherry picked from commit f0d9b8aea94c2a207b7b71faaa7a8a2f78ddf1ea)
f0d9b8aea94c2a207b7b71faaa7a8a2f78ddf1ea 20-Apr-2016 Shubham Ajmera <shubhamajmera@google.com> Add missed overrides for OpenJDK 8 Map default methods

Both the replace methods in TreeMap were left intentionally in the
commit 0e83756c4295f4df3853047205d94fe845573522 as there were no
behavioral differences and the default implementation was considered
sufficient. However, the upstream version is more efficient so that is
being added here.

As of now, all the overrides for the Map default implementation have
been put from the upstream, except for Hashtable and HashMap. Both
of these classes are quite different from their OpenJDK 8 versions to
accommodate the overrides. HashMap depends on the default implementation
for the following methods:

#getOrDefault
#replace(K, V)
#computeIfAbsent
#computeIfPresent
#compute
#merge

#replace(K, V, V) was reimplemented due to the behavioral differences
with the default implementation.

The following Hashtable methods are also dependent on the map default
implementation, though, they have added synchronization.

#getOrDefault
#putIfAbsent
#remove
#replace(K, V, V)
#replace(K, V)
#computeIfAbsent
#computeIfPresent
#compute

Once the classes get ready with the new changes comes with OpenJDK 8,
the above methods would be put in.

Bug: 27426743
Change-Id: Iee4fb156eddee17187386bbfffc8517415030a94
0976dc2e109a3ca2bd977d18eee74e4b7c9ada30 04-Apr-2016 Shubham Ajmera <shubhamajmera@google.com> Add Map::replaceAll method

and corresponding unit test.

Bug: 27426743

(cherry-picked from commit 135ea6cd4f7ebe2f225351a1928d8a62bce5cb00)

Change-Id: Ia86b769fbf5ce55379325ae575d4b3818cb6ccc1
135ea6cd4f7ebe2f225351a1928d8a62bce5cb00 04-Apr-2016 Shubham Ajmera <shubhamajmera@google.com> Add Map::replaceAll method

and corresponding unit test.

Bug: 27426743
Change-Id: Ia86b769fbf5ce55379325ae575d4b3818cb6ccc1
783b17f8bbc4f7077c18c2f83c2cf6d5543f2d19 11-Mar-2016 Narayan Kamath <narayan@google.com> Fix TreeMapTest#test_spliterator_valueSet.

This was an incorrect test. The set of values will only
be sized, not sorted.

bug: 27426688

(cherry picked from commit 9a910a991e203fc3435bc636f12a93107cef37a5)

Change-Id: Ic0c28ae393a63af294bdceaed3ac4766d256a683
9a910a991e203fc3435bc636f12a93107cef37a5 11-Mar-2016 Narayan Kamath <narayan@google.com> Fix TreeMapTest#test_spliterator_valueSet.

This was an incorrect test. The set of values will only
be sized, not sorted.

bug: 27426688
Change-Id: I2b3c601ed9cb7fd8435e80f02be010f84048fe08
8b056f0b15bc1e45da8d4c504353b05e681ac013 04-Mar-2016 Narayan Kamath <narayan@google.com> Add java.lang.Iterable.spliterator() and supporting classes.

The only android specific changes here are to HashMap - their
spliterators add Spliterator.ORDERED if the HashMap is an instance
of a LinkedHashMap.

There's some degree of duplication between the test code used to
exercise primitive arrays (Arrays / Spliterators provide similar
APIs). These differences are quite hard to consolidate, since the
Arrays version declares that their Spliterators are ORDERED but
the Spliterator version doesn't. The latter also allows us to declare
additional Spliterator characteristics.

bug: 27426688
Change-Id: I191a9319d4af7e22834f2d91f73634a227b36bc2
4c89023ef86f29fa9add7db2574f2169fe842577 04-Mar-2016 Narayan Kamath <narayan@google.com> Add java.lang.Iterable.spliterator() and supporting classes.

The only android specific changes here are to HashMap - their
spliterators add Spliterator.ORDERED if the HashMap is an instance
of a LinkedHashMap.

There's some degree of duplication between the test code used to
exercise primitive arrays (Arrays / Spliterators provide similar
APIs). These differences are quite hard to consolidate, since the
Arrays version declares that their Spliterators are ORDERED but
the Spliterator version doesn't. The latter also allows us to declare
additional Spliterator characteristics.

(cherry-picked from commit ed21aa3a8dcd34eca6f0317eeb683e7afdc825b9)

bug: 27426688
Change-Id: I191a9319d4af7e22834f2d91f73634a227b36bc2
78562a12977fc4d81cd31e7c5af05d66bb701ccd 05-Jan-2016 Narayan Kamath <narayan@google.com> Workaround bogus TreeMap Comparators.

Try our best not to compare elements against themselves.

**** THIS CHANGE WILL BE REVERTED IN A FUTURE ANDROID RELEASE ****

bug: 26336181
Change-Id: I67e846159c1be9e9a5595ece5a32a00ff8eacccd
b11ce5f8024d9b7a7a2b7720d48acd2db8c97ec3 10-Dec-2015 Yi Kong <yikong@google.com> Update TreeMapTest golden value

TreeMap changed serialVersionUID, updating the golden value to the new
serialized form to pass the test again.

Bug: 26023477
Change-Id: If500c85560b44f1236fb875374ea6e3dde441ffe
b416ef5dc224630af2b9393a15ae120b27e4864a 14-Dec-2011 Jesse Wilson <jessewilson@google.com> Rename SerializableTester to SerializationTester

Change-Id: Idfaea5c474eb3cabfb8eefc5aa25a7ff0cce26ea
94fab96cd4c1bd4363ba1d70b59475132ddd441e 13-Dec-2011 Jesse Wilson <jessewilson@google.com> Fix serialization of reverse-ordered TreeSets.

Bug: http://b/5552608
Change-Id: I949c2ab11fea391987217dfd5f8dad0cd3fe3fbf
4557728efb66c455a52b7669a8eefef7a9e54854 11-Aug-2010 Jesse Wilson <jessewilson@google.com> Moving tests to be under the libcore.* package.

This is indended to make it easier to run on VMs that restrict the packages
from which application classes can be loaded. For example, on the RI you need
to use the bootclasspath to load these tests.

Change-Id: I52193f35c5fcca18b5a3e1d280505b1e29b388af