| 146 | // CreateNamedDeprecated(openExisting=true) |
| 147 | #if !defined(OS_ANDROID) |
| 148 | TEST(SharedMemoryTest, OpenClose) { |
| 149 | const uint32_t kDataSize = 1024; |
| 150 | std::string test_name = "SharedMemoryOpenCloseTest"; |
| 151 | |
| 152 | // Open two handles to a memory segment, confirm that they are mapped |
| 153 | // separately yet point to the same space. |
| 154 | SharedMemory memory1; |
| 155 | bool rv = memory1.Delete(test_name); |
| 156 | EXPECT_TRUE(rv); |
| 157 | rv = memory1.Delete(test_name); |
| 158 | EXPECT_TRUE(rv); |
| 159 | rv = memory1.Open(test_name, false); |
| 160 | EXPECT_FALSE(rv); |
| 161 | rv = memory1.CreateNamedDeprecated(test_name, false, kDataSize); |
| 162 | EXPECT_TRUE(rv); |
| 163 | rv = memory1.Map(kDataSize); |
| 164 | EXPECT_TRUE(rv); |
| 165 | SharedMemory memory2; |
| 166 | rv = memory2.Open(test_name, false); |
| 167 | EXPECT_TRUE(rv); |
| 168 | rv = memory2.Map(kDataSize); |
| 169 | EXPECT_TRUE(rv); |
| 170 | EXPECT_NE(memory1.memory(), memory2.memory()); // Compare the pointers. |
| 171 | |
| 172 | // Make sure we don't segfault. (it actually happened!) |
| 173 | ASSERT_NE(memory1.memory(), static_cast<void*>(NULL)); |
| 174 | ASSERT_NE(memory2.memory(), static_cast<void*>(NULL)); |
| 175 | |
| 176 | // Write data to the first memory segment, verify contents of second. |
| 177 | memset(memory1.memory(), '1', kDataSize); |
| 178 | EXPECT_EQ(memcmp(memory1.memory(), memory2.memory(), kDataSize), 0); |
| 179 | |
| 180 | // Close the first memory segment, and verify the second has the right data. |
| 181 | memory1.Close(); |
| 182 | char *start_ptr = static_cast<char *>(memory2.memory()); |
| 183 | char *end_ptr = start_ptr + kDataSize; |
| 184 | for (char* ptr = start_ptr; ptr < end_ptr; ptr++) |
| 185 | EXPECT_EQ(*ptr, '1'); |
| 186 | |
| 187 | // Close the second memory segment. |
| 188 | memory2.Close(); |
| 189 | |
| 190 | rv = memory1.Delete(test_name); |
| 191 | EXPECT_TRUE(rv); |
| 192 | rv = memory2.Delete(test_name); |
| 193 | EXPECT_TRUE(rv); |
| 194 | } |
| 195 | |
| 196 | TEST(SharedMemoryTest, OpenExclusive) { |
| 197 | const uint32_t kDataSize = 1024; |
nothing calls this directly
no test coverage detected