Skip to content

Commit 978a945

Browse files
authored
Merge pull request #155 from scratchcpp/scratchconfiguration_test
Add ScratchConfiguration test
2 parents 4eb7b78 + 6251c48 commit 978a945

File tree

12 files changed

+156
-0
lines changed

12 files changed

+156
-0
lines changed

src/scratchconfiguration_p.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
#include <scratchcpp/iextension.h>
4+
#include <algorithm>
45

56
#include "scratchconfiguration_p.h"
67

78
using namespace libscratchcpp;
89

910
void ScratchConfigurationPrivate::registerExtension(std::shared_ptr<IExtension> extension)
1011
{
12+
if (std::find(extensions.begin(), extensions.end(), extension) != extensions.cend())
13+
return;
14+
1115
extensions.push_back(extension);
1216
}
1317

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ add_subdirectory(virtual_machine)
2323
add_subdirectory(scratch_classes)
2424
add_subdirectory(target_interfaces)
2525
add_subdirectory(blocks)
26+
add_subdirectory(scratchconfiguration)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
add_executable(
2+
scratchconfiguration_test
3+
scratchconfiguration_test.cpp
4+
extensionbase.cpp
5+
extensionbase.h
6+
extension1.cpp
7+
extension1.h
8+
extension2.cpp
9+
extension2.h
10+
extension3.cpp
11+
extension3.h
12+
)
13+
14+
target_link_libraries(
15+
scratchconfiguration_test
16+
GTest::gtest_main
17+
scratchcpp
18+
)
19+
20+
gtest_discover_tests(scratchconfiguration_test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "extension1.h"
2+
3+
using namespace libscratchcpp;
4+
5+
std::string Extension1::name() const
6+
{
7+
return "ext 1";
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "extensionbase.h"
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class Extension1 : public ExtensionBase
9+
{
10+
public:
11+
std::string name() const override;
12+
};
13+
14+
} // namespace libscratchcpp
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "extension2.h"
2+
3+
using namespace libscratchcpp;
4+
5+
std::string Extension2::name() const
6+
{
7+
return "ext 2";
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "extensionbase.h"
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class Extension2 : public ExtensionBase
9+
{
10+
public:
11+
std::string name() const override;
12+
};
13+
14+
} // namespace libscratchcpp
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "extension3.h"
2+
3+
using namespace libscratchcpp;
4+
5+
std::string Extension3::name() const
6+
{
7+
return "ext 3";
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "extensionbase.h"
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class Extension3 : public ExtensionBase
9+
{
10+
public:
11+
std::string name() const override;
12+
};
13+
14+
} // namespace libscratchcpp
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "extensionbase.h"
2+
3+
using namespace libscratchcpp;
4+
5+
std::string ExtensionBase::description() const
6+
{
7+
return "";
8+
}
9+
10+
void ExtensionBase::registerSections(IEngine *engine)
11+
{
12+
}

0 commit comments

Comments
 (0)