Debian Codegraph @

closure-library/closure/goog/storage/mechanism/mechanismsharingtester.js

raw
1 // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Unit tests for storage mechanism sharing.
17 *
18 * These tests should be included in tests of any storage mechanism in which
19 * separate mechanism instances share the same underlying storage. Most (if
20 * not all) storage mechanisms should have this property. If the mechanism
21 * employs namespaces, make sure the same namespace is used for both objects.
22 *
23 */
24
25 goog.provide('goog.storage.mechanism.mechanismSharingTester');
26
27 goog.require('goog.iter.StopIteration');
28 /** @suppress {extraRequire} */
29 goog.require('goog.storage.mechanism.mechanismTestDefinition');
30 goog.require('goog.testing.asserts');
31
32
33 goog.setTestOnly('goog.storage.mechanism.mechanismSharingTester');
34
35 function testSharedSet() {
36 if (!mechanism || !mechanism_shared) {
37 return;
38 }
39 mechanism.set('first', 'one');
40 assertEquals('one', mechanism_shared.get('first'));
41 assertEquals(1, mechanism_shared.getCount());
42 var iterator = mechanism_shared.__iterator__();
43 assertEquals('one', iterator.next());
44 assertEquals(goog.iter.StopIteration, assertThrows(iterator.next));
45 }
46
47
48 function testSharedSetInverse() {
49 if (!mechanism || !mechanism_shared) {
50 return;
51 }
52 mechanism_shared.set('first', 'two');
53 assertEquals('two', mechanism.get('first'));
54 assertEquals(1, mechanism.getCount());
55 var iterator = mechanism.__iterator__();
56 assertEquals('two', iterator.next());
57 assertEquals(goog.iter.StopIteration, assertThrows(iterator.next));
58 }
59
60
61 function testSharedRemove() {
62 if (!mechanism || !mechanism_shared) {
63 return;
64 }
65 mechanism_shared.set('first', 'three');
66 mechanism.remove('first');
67 assertNull(mechanism_shared.get('first'));
68 assertEquals(0, mechanism_shared.getCount());
69 assertEquals(
70 goog.iter.StopIteration,
71 assertThrows(mechanism_shared.__iterator__().next));
72 }
73
74
75 function testSharedClean() {
76 if (!mechanism || !mechanism_shared) {
77 return;
78 }
79 mechanism.set('first', 'four');
80 mechanism_shared.clear();
81 assertEquals(0, mechanism.getCount());
82 assertEquals(
83 goog.iter.StopIteration, assertThrows(mechanism.__iterator__().next));
84 }