From 5fc11331954f03c4bd08a959e38cd479ca67b856 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 20 Jan 2015 23:00:08 -0500 Subject: [PATCH] Bug 1124047 - Move TestPriorityQueue.cpp to gtest and enable it; r=froydnj --- xpcom/tests/{ => gtest}/TestPriorityQueue.cpp | 42 +++++-------------- xpcom/tests/gtest/moz.build | 1 + xpcom/tests/moz.build | 1 - 3 files changed, 12 insertions(+), 32 deletions(-) rename xpcom/tests/{ => gtest}/TestPriorityQueue.cpp (60%) diff --git a/xpcom/tests/TestPriorityQueue.cpp b/xpcom/tests/gtest/TestPriorityQueue.cpp similarity index 60% rename from xpcom/tests/TestPriorityQueue.cpp rename to xpcom/tests/gtest/TestPriorityQueue.cpp index 74e86f79effa..7aec8ca009a7 100644 --- a/xpcom/tests/TestPriorityQueue.cpp +++ b/xpcom/tests/gtest/TestPriorityQueue.cpp @@ -7,6 +7,7 @@ #include "nsTPriorityQueue.h" #include #include +#include "gtest/gtest.h" template void @@ -16,32 +17,13 @@ CheckPopSequence(const nsTPriorityQueue& aQueue, nsTPriorityQueue copy(aQueue); for (uint32_t i = 0; i < aSequenceLength; i++) { - if (copy.IsEmpty()) { - printf("Number of elements in the queue is too short by %d.\n", - aSequenceLength - i); - exit(-1); - } + EXPECT_FALSE(copy.IsEmpty()); T pop = copy.Pop(); - if (pop != aExpectedSequence[i]) { - printf("Unexpected value in pop sequence at position %d\n", i); - printf(" Sequence:"); - for (size_t j = 0; j < aSequenceLength; j++) { - printf(" %d", aExpectedSequence[j]); - if (j == i) { - printf("**"); - } - } - printf("\n ** Got %d instead\n", pop); - exit(-1); - } + EXPECT_EQ(pop, aExpectedSequence[i]); } - if (!copy.IsEmpty()) { - printf("Number of elements in the queue is too long by %d.\n", - copy.Length()); - exit(-1); - } + EXPECT_TRUE(copy.IsEmpty()); } template @@ -52,11 +34,11 @@ public: } }; -int main() +TEST(PriorityQueue, Main) { nsTPriorityQueue queue; - NS_ABORT_IF_FALSE(queue.IsEmpty(), "Queue not initially empty"); + EXPECT_TRUE(queue.IsEmpty()); queue.Push(8); queue.Push(6); @@ -64,9 +46,9 @@ int main() queue.Push(2); queue.Push(10); queue.Push(6); - NS_ABORT_IF_FALSE(queue.Top() == 2, "Unexpected queue top"); - NS_ABORT_IF_FALSE(queue.Length() == 6, "Unexpected queue length"); - NS_ABORT_IF_FALSE(!queue.IsEmpty(), "Queue empty when populated"); + EXPECT_EQ(queue.Top(), 2); + EXPECT_EQ(queue.Length(), 6u); + EXPECT_FALSE(queue.IsEmpty()); int expected[] = { 2, 4, 6, 6, 8, 10 }; CheckPopSequence(queue, expected, sizeof(expected) / sizeof(expected[0])); @@ -77,7 +59,7 @@ int main() CheckPopSequence(queue2, expected, sizeof(expected) / sizeof(expected[0])); queue.Clear(); - NS_ABORT_IF_FALSE(queue.IsEmpty(), "Queue not emptied by Clear"); + EXPECT_TRUE(queue.IsEmpty()); // try same sequence with a max heap nsTPriorityQueue > max_queue; @@ -87,10 +69,8 @@ int main() max_queue.Push(2); max_queue.Push(10); max_queue.Push(6); - NS_ABORT_IF_FALSE(max_queue.Top() == 10, "Unexpected queue top for max heap"); + EXPECT_EQ(max_queue.Top(), 10); int expected_max[] = { 10, 8, 6, 6, 4, 2 }; CheckPopSequence(max_queue, expected_max, sizeof(expected_max) / sizeof(expected_max[0])); - - return 0; } diff --git a/xpcom/tests/gtest/moz.build b/xpcom/tests/gtest/moz.build index a244bb605918..2be3491191d8 100644 --- a/xpcom/tests/gtest/moz.build +++ b/xpcom/tests/gtest/moz.build @@ -9,6 +9,7 @@ UNIFIED_SOURCES += [ 'TestEncoding.cpp', 'TestExpirationTracker.cpp', 'TestPipes.cpp', + 'TestPriorityQueue.cpp', 'TestSnappyStreams.cpp', 'TestStrings.cpp', ] diff --git a/xpcom/tests/moz.build b/xpcom/tests/moz.build index de6a36ddeb2a..a451a102923e 100644 --- a/xpcom/tests/moz.build +++ b/xpcom/tests/moz.build @@ -80,7 +80,6 @@ if CONFIG['MOZ_MEMORY']: # XXX Make these tests work in libxul builds. #CPP_UNIT_TESTS += [ -# 'TestPriorityQueue', # 'TestStorageStream', # 'TestSynchronization', # 'TestTArray',