first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <react/utils/SimpleThreadSafeCache.h>
namespace facebook::react {
TEST(EvictingCacheMapTest, BasicInsertAndGet) {
SimpleThreadSafeCache<int, std::string, 3> cache;
EXPECT_EQ(cache.get(1), ""); // Default constructed value is returned
EXPECT_EQ(cache.get(2), ""); // Default constructed value is returned
EXPECT_EQ(cache.get(3), ""); // Default constructed value is returned
cache.get(1, []() { return std::string("one"); });
cache.get(2, []() { return std::string("two"); });
cache.get(3, []() { return std::string("three"); });
EXPECT_EQ(cache.get(1), "one");
EXPECT_EQ(cache.get(2), "two");
EXPECT_EQ(cache.get(3), "three");
}
TEST(EvictingCacheMapTest, Eviction) {
SimpleThreadSafeCache<int, std::string, 2> cache;
cache.get(1, []() { return std::string("one"); });
cache.get(2, []() { return std::string("two"); });
cache.get(3, []() { return std::string("three"); }); // should evict key 1
EXPECT_EQ(
cache.get(1),
""); // key 1 should be evicted and default constructed value is returned
EXPECT_EQ(cache.get(2), "two");
EXPECT_EQ(cache.get(3), "three");
}
} // namespace facebook::react

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <react/utils/Uuid.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace ::testing;
namespace facebook::react {
TEST(UuidTest, TestGenerateRandomUuidString) {
static constexpr auto kUuidV4Regex =
"[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
std::string uuid1 = generateRandomUuidString();
std::string uuid2 = generateRandomUuidString();
EXPECT_THAT(uuid1, MatchesRegex(kUuidV4Regex));
EXPECT_THAT(uuid2, MatchesRegex(kUuidV4Regex));
EXPECT_NE(uuid1, uuid2);
}
} // namespace facebook::react

View File

@@ -0,0 +1,24 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <react/utils/fnv1a.h>
namespace facebook::react {
TEST(fnv1aTests, testBasicHashing) {
EXPECT_EQ(fnv1a("react"), fnv1a("react"));
EXPECT_NE(fnv1a("react"), fnv1a("tceat"));
auto string1 = "case 1";
auto string2 = "different string";
EXPECT_EQ(fnv1a(string1), fnv1a(string1));
EXPECT_NE(fnv1a(string1), fnv1a(string2));
}
} // namespace facebook::react

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <react/utils/hash_combine.h>
struct Person {
std::string firstName;
std::string lastName;
};
namespace std {
template <>
struct hash<Person> {
size_t operator()(const Person& person) const {
return facebook::react::hash_combine(person.firstName, person.lastName);
}
};
} // namespace std
namespace facebook::react {
TEST(hash_combineTests, testIntegerTemplating) {
std::size_t seed = 0;
hash_combine(seed, 1);
auto hashedValue = hash_combine(1);
EXPECT_EQ(hashedValue, seed);
EXPECT_NE(hash_combine(1), hash_combine(2));
}
TEST(hash_combineTests, testIntegerCombinationsHashing) {
std::size_t seed = 0;
hash_combine(seed, 1, 2);
auto hashedValue = hash_combine(1, 2);
EXPECT_EQ(hashedValue, seed);
EXPECT_NE(hash_combine(1, 2), hash_combine(2, 1));
}
TEST(hash_combineTests, testContiniousIntegerHashing) {
std::size_t seed = 0;
for (int i = 1; i <= 200; ++i) {
auto previousSeed = seed;
hash_combine(seed, i);
EXPECT_NE(seed, previousSeed);
}
}
TEST(hash_combineTests, testStrings) {
std::size_t seed = 0;
hash_combine<std::string>(seed, "react");
auto hashedValue = hash_combine<std::string>("react");
EXPECT_EQ(hashedValue, seed);
EXPECT_NE(
hash_combine<std::string>("react"),
hash_combine<std::string>("react native"));
}
TEST(hash_combineTests, testCustomTypes) {
auto person1 = Person{.firstName = "John", .lastName = "Doe"};
auto person2 = Person{.firstName = "Jane", .lastName = "Doe"};
std::size_t seed = 0;
hash_combine(seed, person1);
auto hashedValue = hash_combine(person1);
EXPECT_EQ(hashedValue, seed);
EXPECT_NE(hash_combine(person1), hash_combine(person2));
}
} // namespace facebook::react