mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 22:00:47 +01:00

These are quite generic utilities that are used by multiple modules within dcSCTP. Some would be good to have in rtc_base and are simple replicas of utilities available in abseil. Bug: webrtc:12614 Change-Id: I9914286ced7317a34628a71697da9149d6d19d38 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213190 Reviewed-by: Tommi <tommi@webrtc.org> Commit-Queue: Victor Boivie <boivie@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33609}
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021 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 "net/dcsctp/common/pair_hash.h"
|
|
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
|
|
#include "test/gmock.h"
|
|
|
|
namespace dcsctp {
|
|
namespace {
|
|
|
|
TEST(PairHashTest, CanInsertIntoSet) {
|
|
using MyPair = std::pair<int, int>;
|
|
|
|
std::unordered_set<MyPair, PairHash> pairs;
|
|
|
|
pairs.insert({1, 2});
|
|
pairs.insert({3, 4});
|
|
|
|
EXPECT_NE(pairs.find({1, 2}), pairs.end());
|
|
EXPECT_NE(pairs.find({3, 4}), pairs.end());
|
|
EXPECT_EQ(pairs.find({1, 3}), pairs.end());
|
|
EXPECT_EQ(pairs.find({3, 3}), pairs.end());
|
|
}
|
|
|
|
TEST(PairHashTest, CanInsertIntoMap) {
|
|
using MyPair = std::pair<int, int>;
|
|
|
|
std::unordered_map<MyPair, int, PairHash> pairs;
|
|
|
|
pairs[{1, 2}] = 99;
|
|
pairs[{3, 4}] = 100;
|
|
|
|
EXPECT_EQ((pairs[{1, 2}]), 99);
|
|
EXPECT_EQ((pairs[{3, 4}]), 100);
|
|
EXPECT_EQ(pairs.find({1, 3}), pairs.end());
|
|
EXPECT_EQ(pairs.find({3, 3}), pairs.end());
|
|
}
|
|
} // namespace
|
|
} // namespace dcsctp
|