| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 { } | 94 { } |
| 95 | 95 |
| 96 ~DestructCounter() { ++(*m_destructNumber); } | 96 ~DestructCounter() { ++(*m_destructNumber); } |
| 97 int get() const { return m_i; } | 97 int get() const { return m_i; } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 int m_i; | 100 int m_i; |
| 101 int* m_destructNumber; | 101 int* m_destructNumber; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 typedef WTF::HashMap<int, OwnPtr<DestructCounter> > OwnPtrHashMap; | 104 typedef WTF::HashMap<int, OwnPtr<DestructCounter>> OwnPtrHashMap; |
| 105 | 105 |
| 106 TEST(HashMapTest, OwnPtrAsValue) | 106 TEST(HashMapTest, OwnPtrAsValue) |
| 107 { | 107 { |
| 108 int destructNumber = 0; | 108 int destructNumber = 0; |
| 109 OwnPtrHashMap map; | 109 OwnPtrHashMap map; |
| 110 map.add(1, adoptPtr(new DestructCounter(1, &destructNumber))); | 110 map.add(1, adoptPtr(new DestructCounter(1, &destructNumber))); |
| 111 map.add(2, adoptPtr(new DestructCounter(2, &destructNumber))); | 111 map.add(2, adoptPtr(new DestructCounter(2, &destructNumber))); |
| 112 | 112 |
| 113 DestructCounter* counter1 = map.get(1); | 113 DestructCounter* counter1 = map.get(1); |
| 114 EXPECT_EQ(1, counter1->get()); | 114 EXPECT_EQ(1, counter1->get()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 234 } |
| 235 | 235 |
| 236 class SimpleClass { | 236 class SimpleClass { |
| 237 public: | 237 public: |
| 238 explicit SimpleClass(int v) : m_v(v) { } | 238 explicit SimpleClass(int v) : m_v(v) { } |
| 239 int v() { return m_v; } | 239 int v() { return m_v; } |
| 240 | 240 |
| 241 private: | 241 private: |
| 242 int m_v; | 242 int m_v; |
| 243 }; | 243 }; |
| 244 typedef HashMap<int, OwnPtr<SimpleClass> > IntSimpleMap; | 244 typedef HashMap<int, OwnPtr<SimpleClass>> IntSimpleMap; |
| 245 | 245 |
| 246 TEST(HashMapTest, AddResult) | 246 TEST(HashMapTest, AddResult) |
| 247 { | 247 { |
| 248 IntSimpleMap map; | 248 IntSimpleMap map; |
| 249 IntSimpleMap::AddResult result = map.add(1, nullptr); | 249 IntSimpleMap::AddResult result = map.add(1, nullptr); |
| 250 EXPECT_TRUE(result.isNewEntry); | 250 EXPECT_TRUE(result.isNewEntry); |
| 251 EXPECT_EQ(1, result.storedValue->key); | 251 EXPECT_EQ(1, result.storedValue->key); |
| 252 EXPECT_EQ(0, result.storedValue->value.get()); | 252 EXPECT_EQ(0, result.storedValue->value.get()); |
| 253 | 253 |
| 254 SimpleClass* simple1 = new SimpleClass(1); | 254 SimpleClass* simple1 = new SimpleClass(1); |
| 255 result.storedValue->value = adoptPtr(simple1); | 255 result.storedValue->value = adoptPtr(simple1); |
| 256 EXPECT_EQ(simple1, map.get(1)); | 256 EXPECT_EQ(simple1, map.get(1)); |
| 257 | 257 |
| 258 IntSimpleMap::AddResult result2 = map.add(1, adoptPtr(new SimpleClass(2))); | 258 IntSimpleMap::AddResult result2 = map.add(1, adoptPtr(new SimpleClass(2))); |
| 259 EXPECT_FALSE(result2.isNewEntry); | 259 EXPECT_FALSE(result2.isNewEntry); |
| 260 EXPECT_EQ(1, map.get(1)->v()); | 260 EXPECT_EQ(1, map.get(1)->v()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // namespace | 263 } // namespace |
| OLD | NEW |