chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:47:42 +08:00
commit be3ef883e1
1214 changed files with 431743 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+48
View File
@@ -0,0 +1,48 @@
// Copyright 2025-present the zvec project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <zvec/ailego/pattern/factory.h>
using namespace zvec;
using namespace zvec::ailego;
struct Base {
virtual ~Base(void) {}
virtual void do_something() = 0;
};
struct AAA : public Base {
AAA(void) {}
void do_something() override {
printf("do something\n");
}
};
AILEGO_FACTORY_REGISTER(AAA, Base, AAA);
TEST(Factory, General) {
EXPECT_TRUE(!ailego::Factory<Base>::MakeShared("BBB"));
EXPECT_TRUE(!ailego::Factory<Base>::Has("BBB"));
auto aaa = ailego::Factory<Base>::MakeShared("AAA");
ASSERT_TRUE(!!aaa);
aaa->do_something();
EXPECT_TRUE(!!ailego::Factory<Base>::Has("AAA"));
auto vec = ailego::Factory<Base>::Classes();
EXPECT_EQ(1u, vec.size());
EXPECT_EQ("AAA", std::string(vec[0]));
}
+102
View File
@@ -0,0 +1,102 @@
// Copyright 2025-present the zvec project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <ailego/pattern/defer.h>
#include <gtest/gtest.h>
using namespace zvec;
TEST(ScopeGuard, Lambda) {
int count = 0;
auto a = ailego::ScopeGuard::Make(
[](int val) { printf("ScopeGuard: Lambda %d\n", val); }, 1);
auto b = ailego::ScopeGuard::Make([&] {
printf("ScopeGuard: Lambda 2\n");
++count;
});
auto c = ailego::ScopeGuard::Make([] {
printf("ScopeGuard: Lambda 3\n");
return 0;
});
auto d = ailego::ScopeGuard::Make([&] {
printf("ScopeGuard: Lambda 4\n");
++count;
return false;
});
EXPECT_EQ(0, count);
}
struct ClassA {
static void StaticProcess0(void) {
printf("ScopeGuard: Static Function 1\n");
++count;
}
static int StaticProcess1(int val) {
printf("ScopeGuard: Static Function %d\n", val);
++count;
return 0;
}
static int count;
};
int ClassA::count{0};
TEST(ScopeGuard, StaticFunction) {
auto a = ailego::ScopeGuard::Make(ClassA::StaticProcess0);
auto b = ailego::ScopeGuard::Make(ClassA::StaticProcess1, 2);
EXPECT_EQ(0, ClassA::count);
}
class ClassB {
public:
virtual void MemberProcess0(void) const {
printf("ScopeGuard: Member Function 0\n");
++count;
}
virtual void MemberProcess1(int val) {
printf("ScopeGuard: Member Function %d\n", val);
++count;
}
virtual void MemberProcess2(long val) const volatile {
printf("ScopeGuard: Member Function %ld\n", val);
++count;
}
virtual void MemberProcess3(size_t val) volatile {
printf("ScopeGuard: Member Function %zu\n", val);
++count;
}
static int count;
};
int ClassB::count{0};
TEST(ScopeGuard, MemberFunction) {
ClassB bb;
auto a = ailego::ScopeGuard::Make(&bb, &ClassB::MemberProcess0);
auto b = ailego::ScopeGuard::Make(&bb, &ClassB::MemberProcess1, 2);
AILEGO_DEFER(&bb, &ClassB::MemberProcess2, 3);
AILEGO_DEFER(&bb, &ClassB::MemberProcess3, 4);
EXPECT_EQ(0, ClassB::count);
}
+45
View File
@@ -0,0 +1,45 @@
// Copyright 2025-present the zvec project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <zvec/ailego/parallel/thread_pool.h>
#include <zvec/ailego/pattern/singleton.h>
using namespace zvec::ailego;
struct AAA {
void run() {
++a;
}
uint32_t val() {
return a;
}
std::atomic_uint a{0};
};
TEST(Singleton, General) {
Singleton<int>::Instance() = 15;
EXPECT_EQ(15, Singleton<int>::Instance());
Singleton<double>::Instance() = 1.2;
EXPECT_DOUBLE_EQ(1.2, Singleton<double>::Instance());
ThreadPool pool1;
for (int i = 0; i < 1000; ++i) {
pool1.execute([] { Singleton<AAA>::Instance().run(); });
}
pool1.wait_finish();
EXPECT_EQ(1000u, Singleton<AAA>::Instance().val());
}