File tree Expand file tree Collapse file tree 6 files changed +98
-0
lines changed
Expand file tree Collapse file tree 6 files changed +98
-0
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,15 @@ target_sources(scratchcpp
99 projecturl.cpp
1010 projecturl.h
1111 idownloader.h
12+ idownloaderfactory.h
1213)
1314
1415if (LIBSCRATCHCPP_NETWORK_SUPPORT)
1516 target_sources (scratchcpp
1617 PRIVATE
1718 downloader.cpp
1819 downloader.h
20+ downloaderfactory.cpp
21+ downloaderfactory.h
1922 )
2023endif ()
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include " downloaderfactory.h"
4+ #include " downloader.h"
5+
6+ using namespace libscratchcpp ;
7+
8+ std::shared_ptr<DownloaderFactory> DownloaderFactory::m_instance = std::make_shared<DownloaderFactory>();
9+
10+ DownloaderFactory::DownloaderFactory ()
11+ {
12+ }
13+
14+ std::shared_ptr<DownloaderFactory> DownloaderFactory::instance ()
15+ {
16+ return m_instance;
17+ }
18+
19+ std::shared_ptr<IDownloader> DownloaderFactory::create () const
20+ {
21+ return std::make_shared<Downloader>();
22+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include " idownloaderfactory.h"
6+
7+ namespace libscratchcpp
8+ {
9+
10+ class DownloaderFactory : public IDownloaderFactory
11+ {
12+ public:
13+ DownloaderFactory ();
14+
15+ static std::shared_ptr<DownloaderFactory> instance ();
16+ std::shared_ptr<IDownloader> create () const override ;
17+
18+ private:
19+ static std::shared_ptr<DownloaderFactory> m_instance;
20+ };
21+
22+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include < memory>
6+
7+ namespace libscratchcpp
8+ {
9+
10+ class IDownloader ;
11+
12+ class IDownloaderFactory
13+ {
14+ public:
15+ virtual ~IDownloaderFactory () { }
16+
17+ virtual std::shared_ptr<IDownloader> create () const = 0;
18+ };
19+
20+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -11,3 +11,20 @@ target_link_libraries(
1111)
1212
1313gtest_discover_tests(projecturl_test)
14+
15+ if (LIBSCRATCHCPP_NETWORK_SUPPORT)
16+ # downloaderfactory_test
17+ add_executable (
18+ downloaderfactory_test
19+ downloaderfactory_test.cpp
20+ )
21+
22+ target_link_libraries (
23+ downloaderfactory_test
24+ GTest::gtest_main
25+ scratchcpp
26+ cpr::cpr
27+ )
28+
29+ gtest_discover_tests(downloaderfactory_test)
30+ endif ()
Original file line number Diff line number Diff line change 1+ #include < internal/downloaderfactory.h>
2+ #include < internal/downloader.h>
3+
4+ #include " ../common.h"
5+
6+ using namespace libscratchcpp ;
7+
8+ TEST (DownloaderFactoryTest, Create)
9+ {
10+ auto factory = DownloaderFactory::instance ();
11+ std::shared_ptr<IDownloader> downloader = factory->create ();
12+ ASSERT_TRUE (downloader);
13+ ASSERT_TRUE (std::dynamic_pointer_cast<Downloader>(downloader));
14+ }
You can’t perform that action at this time.
0 commit comments