diff --git a/.gitmodules b/.gitmodules index 708142795..61acc85c0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,7 @@ [submodule "assets/config/MaaAgentBinary"] path = assets/config/MaaAgentBinary url = https://github.com/MaaAssistantArknights/MaaAgentBinary.git +[submodule "test/TestingSet"] + path = test/TestingSet + url = https://github.com/MaaAssistantArknights/MaaFwTestingSet.git + branch = master diff --git a/3rdparty/include/meojson/json.hpp b/3rdparty/include/meojson/json.hpp index e3cbc8e55..8e9711a09 100644 --- a/3rdparty/include/meojson/json.hpp +++ b/3rdparty/include/meojson/json.hpp @@ -532,6 +532,10 @@ class exception : public std::exception template auto parse(const parsing_t& content); + +template +auto parse(char_t* content); + template , istream_t>>> auto parse(istream_t& istream, bool check_bom); @@ -2372,6 +2376,12 @@ MEOJSON_INLINE auto parse(const parsing_t& content) return parser::parse(content); } +template +MEOJSON_INLINE auto parse(char_t* content) +{ + return parse(std::basic_string_view> { content }); +} + template MEOJSON_INLINE auto parse(istream_t& ifs, bool check_bom) { diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ed4002a9..a6ca96451 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,12 @@ set(CMAKE_MAP_IMPORTED_CONFIG_DebWithRelDeps "DebWithRelDeps;Release;") set(Boost_NO_WARN_NEW_VERSIONS 1) option(USE_MAADEPS "use third-party libraries built by MaaDeps" ON) -option(BUILD_SAMPLE "build a demo" OFF) option(WITH_ADB_CONTROLLER "build with adb controller" ON) option(WITH_THRIFT_CONTROLLER "build with thrift controller" ON) option(WITH_DEBUGGING_CONTROLLER "build with debugging controller" ON) option(WITH_GRPC "build with protobuf and grpc" ON) +option(BUILD_SAMPLE "build a demo" OFF) +option(BUILD_TESTING "build testing" OFF) if(USE_MAADEPS) include(${PROJECT_SOURCE_DIR}/MaaDeps/maadeps.cmake) @@ -61,6 +62,10 @@ add_subdirectory(source) if(BUILD_SAMPLE) add_subdirectory(sample/cpp) endif() +if (BUILD_TESTING) + add_subdirectory(test/source) + add_subdirectory(test/TestingSet) +endif() if(USE_MAADEPS) maadeps_install(bin) diff --git a/source/MaaDebuggingControlUnit/ControlUnitMgr.cpp b/source/MaaDebuggingControlUnit/ControlUnitMgr.cpp index 1d823933c..de6d1633c 100644 --- a/source/MaaDebuggingControlUnit/ControlUnitMgr.cpp +++ b/source/MaaDebuggingControlUnit/ControlUnitMgr.cpp @@ -13,10 +13,11 @@ MAA_DBG_CTRL_UNIT_NS_BEGIN std::shared_ptr create_controller_unit(MaaStringView read_path, MaaStringView wirte_path, MaaDebuggingControllerType type, MaaStringView config) { - LogFunc << VAR(read_path) << VAR(wirte_path) << VAR(type); + LogFunc << VAR(read_path) << VAR(wirte_path) << VAR(type) << VAR(config); auto filepath = MAA_NS::path(read_path); std::ignore = wirte_path; + json::value jconfig = json::parse(config).value_or(json::object()); std::shared_ptr screencap_unit = nullptr; auto screencap_type = type & MaaDebuggingControllerType_Screencap_Mask; @@ -28,9 +29,9 @@ std::shared_ptr create_controller_unit(MaaStringView read_path, } auto device_info_unit = std::make_shared(filepath); - bool parsed = device_info_unit->parse(config); + bool parsed = device_info_unit->parse(jconfig); if (!parsed) { - LogError << "failed to parse config" << VAR(config); + LogError << "failed to parse config" << VAR(jconfig); return nullptr; } diff --git a/source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp index 91d1b6b9b..60e9edb7f 100644 --- a/source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp +++ b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp @@ -6,25 +6,27 @@ MAA_DBG_CTRL_UNIT_NS_BEGIN -ReadIndex::ReadIndex(std::filesystem::path indexfile) : indexfile_(std::move(indexfile)) {} +ReadIndex::ReadIndex(std::filesystem::path root) : root_(std::move(root)) {} bool ReadIndex::init(int swidth, int sheight) { - LogInfo << VAR(indexfile_) << VAR(swidth) << VAR(sheight); + LogInfo << VAR(root_) << VAR(swidth) << VAR(sheight); swidth_ = swidth; sheight_ = sheight; filepaths_.clear(); index_ = 0; - if (!std::filesystem::exists(indexfile_)) { - LogError << "indexfile not exist" << VAR(indexfile_); + if (!std::filesystem::exists(root_)) { + LogError << "root not exist" << VAR(root_); return false; } - std::ifstream ifs(indexfile_); + auto imagelist = root_ / "imagelist.txt"; + + std::ifstream ifs(imagelist); if (!ifs.is_open()) { - LogError << "open indexfile failed" << VAR(indexfile_); + LogError << "open root failed" << VAR(root_); return false; } @@ -39,7 +41,7 @@ bool ReadIndex::init(int swidth, int sheight) image_path = line; } else { - image_path = indexfile_.parent_path() / line; + image_path = imagelist.parent_path() / line; } if (!std::filesystem::exists(image_path)) { LogError << "image not exist" << VAR(image_path); diff --git a/source/MaaDebuggingControlUnit/Screencap/ReadIndex.h b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.h index 1be1fdcc5..d6156c322 100644 --- a/source/MaaDebuggingControlUnit/Screencap/ReadIndex.h +++ b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.h @@ -9,7 +9,7 @@ MAA_DBG_CTRL_UNIT_NS_BEGIN class ReadIndex : public ScreencapAPI { public: - ReadIndex(std::filesystem::path indexfile); + ReadIndex(std::filesystem::path root); virtual ~ReadIndex() override = default; public: // from ScreencapAPI @@ -21,7 +21,7 @@ class ReadIndex : public ScreencapAPI int swidth_ = 0; int sheight_ = 0; - std::filesystem::path indexfile_; + std::filesystem::path root_; std::vector filepaths_; size_t index_ = 0; }; diff --git a/source/MaaFramework/API/MaaController.cpp b/source/MaaFramework/API/MaaController.cpp index f8efc2511..97fe7f760 100644 --- a/source/MaaFramework/API/MaaController.cpp +++ b/source/MaaFramework/API/MaaController.cpp @@ -42,6 +42,8 @@ MaaControllerHandle MaaAdbControllerCreateV2(MaaStringView adb_path, MaaStringVi #pragma message("The build without adb controller") + std::ignore = config; + LogError << "The build without adb controller"; return nullptr; @@ -106,6 +108,8 @@ MaaControllerHandle MaaDebuggingControllerCreate(MaaStringView read_path, MaaStr #pragma message("The build without debugging controller") + std::ignore = config; + LogError << "The build without debugging controller"; return nullptr; diff --git a/source/MaaToolKit/CMakeLists.txt b/source/MaaToolKit/CMakeLists.txt index 61302659b..301445f63 100644 --- a/source/MaaToolKit/CMakeLists.txt +++ b/source/MaaToolKit/CMakeLists.txt @@ -18,9 +18,15 @@ target_include_directories( target_compile_definitions(MaaToolKit PRIVATE MAA_TOOLKIT_EXPORTS) -target_link_libraries(MaaToolKit MaaFramework MaaUtils MaaAdbControlUnit HeaderOnlyLibraries Boost::system) - -add_dependencies(MaaToolKit MaaFramework MaaUtils MaaAdbControlUnit) +target_link_libraries(MaaToolKit MaaFramework MaaUtils HeaderOnlyLibraries Boost::system) +if (WITH_ADB_CONTROLLER) + target_link_libraries(MaaFramework MaaAdbControlUnit) +endif(WITH_ADB_CONTROLLER) + +add_dependencies(MaaToolKit MaaFramework MaaUtils) +if (WITH_ADB_CONTROLLER) + add_dependencies(MaaFramework MaaAdbControlUnit) +endif(WITH_ADB_CONTROLLER) install( TARGETS MaaToolKit diff --git a/source/MaaToolKit/Device/DeviceMgr.cpp b/source/MaaToolKit/Device/DeviceMgr.cpp index dc968e23f..cce032fef 100644 --- a/source/MaaToolKit/Device/DeviceMgr.cpp +++ b/source/MaaToolKit/Device/DeviceMgr.cpp @@ -36,6 +36,8 @@ std::vector DeviceMgr::request_adb_serials(const std::filesystem::p { LogFunc << VAR(adb_path); +#ifdef WITH_ADB_CONTROLLER + std::string str_adb = path_to_utf8_string(adb_path); std::string str_config = adb_config.to_string(); auto mgr = MAA_ADB_CTRL_UNIT_NS::create_device_list_obj(str_adb.c_str(), str_config.c_str()); @@ -50,6 +52,13 @@ std::vector DeviceMgr::request_adb_serials(const std::filesystem::p } return *devices_opt; + +#else + + std::ignore = adb_config; + return {}; + +#endif } bool DeviceMgr::request_adb_connect(const std::filesystem::path& adb_path, const std::string& serial, @@ -57,6 +66,8 @@ bool DeviceMgr::request_adb_connect(const std::filesystem::path& adb_path, const { LogFunc << VAR(adb_path) << VAR(serial); +#ifdef WITH_ADB_CONTROLLER + std::string str_adb = path_to_utf8_string(adb_path); std::string str_config = adb_config.to_string(); auto mgr = MAA_ADB_CTRL_UNIT_NS::create_connection(str_adb.c_str(), serial.c_str(), 0, str_config.c_str()); @@ -66,6 +77,13 @@ bool DeviceMgr::request_adb_connect(const std::filesystem::path& adb_path, const } return mgr->connect(); + +#else + + std::ignore = adb_config; + return false; + +#endif } std::vector DeviceMgr::check_available_adb_serials(const std::filesystem::path& adb_path, diff --git a/test/TestingSet b/test/TestingSet new file mode 160000 index 000000000..043fb8228 --- /dev/null +++ b/test/TestingSet @@ -0,0 +1 @@ +Subproject commit 043fb822804fbf8486e1a43b61c45bfcdd12f5cf diff --git a/test/source/CMakeLists.txt b/test/source/CMakeLists.txt new file mode 100644 index 000000000..b4ce6ff72 --- /dev/null +++ b/test/source/CMakeLists.txt @@ -0,0 +1,14 @@ +file( + GLOB_RECURSE + testing_src + *.cpp + *.h + *.hpp) + +add_executable(testing ${testing_src}) + +target_link_libraries(testing MaaFramework) + +add_dependencies(testing MaaFramework) + +install(TARGETS testing RUNTIME DESTINATION bin) diff --git a/test/source/main.cpp b/test/source/main.cpp new file mode 100644 index 000000000..f83c9c3a4 --- /dev/null +++ b/test/source/main.cpp @@ -0,0 +1,19 @@ +#include + +#include "module/PipelineSmoking.h" + +#include "MaaFramework/MaaAPI.h" + +int main([[maybe_unused]] int argc, char** argv) +{ + auto cur_dir = std::filesystem::path(argv[0]).parent_path(); + + std::string logging_dir = (cur_dir / "debug").string(); + MaaSetGlobalOption(MaaGlobalOption_Logging, (void*)logging_dir.c_str(), logging_dir.size()); + bool on = true; + MaaSetGlobalOption(MaaGlobalOption_DebugMode, &on, sizeof(on)); + + bool ret = pipeline_smoking(cur_dir); + + return ret ? 0 : -1; +} diff --git a/test/source/module/PipelineSmoking.cpp b/test/source/module/PipelineSmoking.cpp new file mode 100644 index 000000000..aecd87d40 --- /dev/null +++ b/test/source/module/PipelineSmoking.cpp @@ -0,0 +1,57 @@ +#include "PipelineSmoking.h" + +#include + +#include + +#include "MaaFramework/MaaAPI.h" + +bool pipeline_smoking(const std::filesystem::path& cur_dir) +{ + auto testing_path = cur_dir.parent_path() / "test" / "PipelineSmoking"; + auto result_path = cur_dir / "debug"; + json::value debug_config = { { "device_info", json::object { + { "uuid", testing_path.string() }, + { "screen_width", 1280 }, + { "screen_height", 720 }, + { "orientation", 0 }, + } } }; + auto config = debug_config.dumps(4); + + auto controller_handle = + MaaDebuggingControllerCreate(testing_path.string().c_str(), result_path.string().c_str(), + MaaDebuggingControllerType_Screencap_ReadIndex, config.c_str(), nullptr, nullptr); + + auto ctrl_id = MaaControllerPostConnection(controller_handle); + + auto resource_handle = MaaResourceCreate(nullptr, nullptr); + auto resource_dir = cur_dir.parent_path() / "test" / "PipelineSmoking" / "resource"; + auto res_id = MaaResourcePostPath(resource_handle, resource_dir.string().c_str()); + + MaaControllerWait(controller_handle, ctrl_id); + MaaResourceWait(resource_handle, res_id); + + auto maa_handle = MaaCreate(nullptr, nullptr); + MaaBindResource(maa_handle, resource_handle); + MaaBindController(maa_handle, controller_handle); + + auto destroy = [&]() { + MaaDestroy(maa_handle); + MaaResourceDestroy(resource_handle); + MaaControllerDestroy(controller_handle); + }; + + if (!MaaInited(maa_handle)) { + std::cout << __FUNCTION__ << " | Failed to init" << std::endl; + + destroy(); + return false; + } + + auto task_id = MaaPostTask(maa_handle, "Wilderness", MaaTaskParam_Empty); + MaaWaitTask(maa_handle, task_id); + + destroy(); + + return true; +} diff --git a/test/source/module/PipelineSmoking.h b/test/source/module/PipelineSmoking.h new file mode 100644 index 000000000..5a40872cf --- /dev/null +++ b/test/source/module/PipelineSmoking.h @@ -0,0 +1,3 @@ +#include + +bool pipeline_smoking(const std::filesystem::path& cur_dir);