Debian Codegraph @

closure-library/closure/goog/storage/mechanism/mechanismseparationtester.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 separation.
17 *
18 * These tests should be included by tests of any mechanism which natively
19 * implements namespaces. There is no need to include those tests for mechanisms
20 * extending goog.storage.mechanism.PrefixedMechanism. Make sure a different
21 * namespace is used for each object.
22 *
23 */
24
25 goog.provide('goog.storage.mechanism.mechanismSeparationTester');
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 goog.setTestOnly('goog.storage.mechanism.mechanismSeparationTester');
33
34
35 function testSeparateSet() {
36 if (!mechanism || !mechanism_separate) {
37 return;
38 }
39 mechanism.set('first', 'one');
40 assertNull(mechanism_separate.get('first'));
41 assertEquals(0, mechanism_separate.getCount());
42 assertEquals(
43 goog.iter.StopIteration,
44 assertThrows(mechanism_separate.__iterator__().next));
45 }
46
47
48 function testSeparateSetInverse() {
49 if (!mechanism || !mechanism_separate) {
50 return;
51 }
52 mechanism.set('first', 'one');
53 mechanism_separate.set('first', 'two');
54 assertEquals('one', mechanism.get('first'));
55 assertEquals(1, mechanism.getCount());
56 var iterator = mechanism.__iterator__();
57 assertEquals('one', iterator.next());
58 assertEquals(goog.iter.StopIteration, assertThrows(iterator.next));
59 }
60
61
62 function testSeparateRemove() {
63 if (!mechanism || !mechanism_separate) {
64 return;
65 }
66 mechanism.set('first', 'one');
67 mechanism_separate.remove('first');
68 assertEquals('one', mechanism.get('first'));
69 assertEquals(1, mechanism.getCount());
70 var iterator = mechanism.__iterator__();
71 assertEquals('one', iterator.next());
72 assertEquals(goog.iter.StopIteration, assertThrows(iterator.next));
73 }
74
75
76 function testSeparateClean() {
77 if (!mechanism || !mechanism_separate) {
78 return;
79 }
80 mechanism_separate.set('first', 'two');
81 mechanism.clear();
82 assertEquals('two', mechanism_separate.get('first'));
83 assertEquals(1, mechanism_separate.getCount());
84 var iterator = mechanism_separate.__iterator__();
85 assertEquals('two', iterator.next());
86 assertEquals(goog.iter.StopIteration, assertThrows(iterator.next));
87 }