- Notifications
You must be signed in to change notification settings - Fork3
Scoped Storage and static Storage class#205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
d4f3614 Added scoped storage to env
coder13744774b8 Added unit tests
coder137b8bbb74 Added storage static class
coder13738c5f7c Updated test_storaget.cpp
coder13736e954e Update buildcc.h
coder137b7397e7 Removed test_persistent_storage
coder137475bfbf Removed persistent_storage.h from args
coder1379d79b10 Updated args CMakeLists.txt
coder137bf3675a Updated build files with ScopedStorage
coder137File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletionbootstrap/include/bootstrap/build_buildcc.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionbuildcc/buildcc.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletionsbuildcc/lib/args/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletionsbuildcc/lib/args/test/test_persistent_storage.cpp
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
8 changes: 8 additions & 0 deletionsbuildcc/lib/env/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
43 changes: 37 additions & 6 deletions...ib/args/include/args/persistent_storage.h → buildcc/lib/env/include/env/storage.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletionsbuildcc/lib/env/src/storage.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Copyright 2021-2022 Niket Naidu. All rights reserved. | ||
| * | ||
| * 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 "env/storage.h" | ||
| namespace buildcc { | ||
| std::unique_ptr<ScopedStorage> Storage::internal_; | ||
| } |
91 changes: 91 additions & 0 deletionsbuildcc/lib/env/test/test_storage.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #include "env/storage.h" | ||
| // NOTE, Make sure all these includes are AFTER the system and header includes | ||
| #include "CppUTest/CommandLineTestRunner.h" | ||
| #include "CppUTest/MemoryLeakDetectorNewMacros.h" | ||
| #include "CppUTest/TestHarness.h" | ||
| #include "CppUTest/Utest.h" | ||
| #include "CppUTestExt/MockSupport.h" | ||
| // clang-format off | ||
| TEST_GROUP(ScopedStorageTestGroup) | ||
| { | ||
| }; | ||
| TEST_GROUP(StorageTestGroup) | ||
| { | ||
| void setup() { | ||
| buildcc::Storage::Init(); | ||
| } | ||
| void teardown() { | ||
| buildcc::Storage::Deinit(); | ||
| } | ||
| }; | ||
| // clang-format on | ||
| class BigObj {}; | ||
| class BigObjWithParameters { | ||
| public: | ||
| BigObjWithParameters(const std::string &name, int id, const BigObj &obj) | ||
| : name_(name) { | ||
| (void)id; | ||
| (void)obj; | ||
| } | ||
| const std::string &GetName() const { return name_; } | ||
| private: | ||
| std::string name_; | ||
| }; | ||
| static BigObj obj; | ||
| TEST(ScopedStorageTestGroup, BasicUsage) { | ||
| buildcc::ScopedStorage storage; | ||
| storage.Add<BigObjWithParameters>("identifier", "name", 10, obj); | ||
| storage.Add<BigObjWithParameters>("identifier2", "name2", 12, obj); | ||
| // Usage | ||
| storage.ConstRef<BigObjWithParameters>("identifier").GetName(); | ||
| storage.Ref<BigObjWithParameters>("identifier2").GetName(); | ||
| // Automatic cleanup here | ||
| } | ||
| TEST(ScopedStorageTestGroup, IncorrectUsage) { | ||
| buildcc::ScopedStorage storage; | ||
| storage.Add<BigObjWithParameters>("identifier", "name", 10, obj); | ||
| // We try to cast to a different type! | ||
| CHECK_THROWS(std::exception, storage.Ref<BigObj>("identifier")); | ||
| // We use a wrong identifier | ||
| CHECK_THROWS(std::exception, | ||
| storage.Ref<BigObjWithParameters>("identifier2")); | ||
| } | ||
| std::string &toReference(std::string *pointer) { return *pointer; } | ||
| TEST(ScopedStorageTestGroup, NullptrDelete) { | ||
| buildcc::ScopedStorage storage; | ||
| storage.Remove<std::string>(nullptr); | ||
| } | ||
| TEST(StorageTestGroup, BasicUsage) { | ||
| buildcc::Storage::Add<BigObjWithParameters>("identifier", "name", 10, obj); | ||
| buildcc::Storage::Add<BigObjWithParameters>("identifier2", "name2", 12, obj); | ||
| // Usage | ||
| const auto &bigobj = | ||
| buildcc::Storage::ConstRef<BigObjWithParameters>("identifier").GetName(); | ||
| const auto &bigobj2 = | ||
| buildcc::Storage::Ref<BigObjWithParameters>("identifier2").GetName(); | ||
| STRCMP_EQUAL(bigobj.c_str(), "name"); | ||
| STRCMP_EQUAL(bigobj2.c_str(), "name2"); | ||
| } | ||
| int main(int ac, char **av) { | ||
| return CommandLineTestRunner::RunAllTests(ac, av); | ||
| } |
2 changes: 1 addition & 1 deletionbuildexe/include/buildexe/build_env_setup.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.