/* * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
#include"rtc_base/swap_queue.h"
#include <cstdint> #include <vector>
#include"test/gtest.h"
namespace webrtc {
namespace {
// Test parameter for the basic sample based SwapQueue Tests. const size_t kChunkSize = 3;
// Queue item verification function for the vector test. bool LengthVerifierFunction(const std::vector<int>& v) { return v.size() == kChunkSize;
}
// Queue item verifier for the vector test. class LengthVerifierFunctor { public: explicit LengthVerifierFunctor(size_t length) : length_(length) {}
// Fill the queue. int i = 0;
EXPECT_TRUE(queue.Insert(&i));
i = 1;
EXPECT_TRUE(queue.Insert(&i));
// Ensure that the value is not swapped when doing an Insert // on a full queue.
i = 2;
EXPECT_FALSE(queue.Insert(&i));
EXPECT_EQ(i, 2);
// Ensure that the Insert didn't overwrite anything in the queue.
EXPECT_TRUE(queue.Remove(&i));
EXPECT_EQ(i, 0);
EXPECT_TRUE(queue.Remove(&i));
EXPECT_EQ(i, 1);
}
TEST(SwapQueueTest, EmptyQueue) {
SwapQueue<int> queue(2); int i = 0;
EXPECT_FALSE(queue.Remove(&i));
EXPECT_TRUE(queue.Insert(&i));
EXPECT_TRUE(queue.Remove(&i));
EXPECT_FALSE(queue.Remove(&i));
}
TEST(SwapQueueTest, Clear) {
SwapQueue<int> queue(2); int i = 0;
// Fill the queue.
EXPECT_TRUE(queue.Insert(&i));
EXPECT_TRUE(queue.Insert(&i));
// Ensure full queue.
EXPECT_FALSE(queue.Insert(&i));
// Empty the queue.
queue.Clear();
// Ensure that the queue is empty
EXPECT_FALSE(queue.Remove(&i));
// Ensure that the queue is no longer full.
EXPECT_TRUE(queue.Insert(&i));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.