Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/story-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
repository: dayfine/PokemonSimulation
# Synthetic contract cases, not an approved map/resource pin.
ref: 866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3
ref: 4e023f3d57022c68018f95f6fc0a4c0722d53adf
path: publisher
- uses: actions/setup-python@v6
with:
Expand All @@ -28,3 +28,7 @@ jobs:
- run: cmake -S devtools/story-data-tests -B build-story-data -DCMAKE_BUILD_TYPE=Debug
- run: cmake --build build-story-data --config Debug -j4
- run: ctest --test-dir build-story-data -C Debug --output-on-failure
- if: runner.os != 'Windows'
run: ./build-story-data/StoryDataTests publisher/data/story/wire-conformance.json
- if: runner.os == 'Windows'
run: ./build-story-data/Debug/StoryDataTests.exe publisher/data/story/wire-conformance.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
* From: https://github.com/PokemonAutomation/
*
* Each case reads a record from JSON: accepted cases check the values
* read, rejected cases check that the read fails. The Python reader's
* shared case file is checked on the Python side.
* read, rejected cases check that the read fails. The standalone
* StoryDataTests also checks PokemonSimulation's shared case file when given
* its path (devtools/story-data-tests/StoryWireCases.h).
*
*/

#include <cstdint>
#include <format>
#include <iostream>
#include <optional>
#include <string>
#include <string_view>
#include <variant>
#include <vector>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/Json/JsonValue.h"
#include "Pokemon/AutoStory/Types/Pokemon_DeclaredPose.h"
#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h"
#include "Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h"
#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h"
#include "Pokemon/Navigation/Pokemon_Direction.h"
#include "Pokemon_StoryStepJson.h"
#ifndef PA_STORY_DATA_STANDALONE
#include "Pokemon_StoryStepJson_Tests.h"
#endif

namespace PokemonAutomation{
namespace Pokemon{
Expand Down Expand Up @@ -269,24 +275,21 @@ void add_tests_StoryStepJson(UnitTestDatabase& database){
}
}

#endif



} // namespace Pokemon
} // namespace PokemonAutomation


#ifdef PA_STORY_DATA_STANDALONE
#else

int main(){
int failed = 0;
for (const auto& test : PokemonAutomation::Pokemon::CASES){
const std::string error = PokemonAutomation::Pokemon::check_case(test);
size_t run_story_step_json_cases(){
size_t failed = 0;
for (const WireCase& test : CASES){
const std::string error = check_case(test);
std::cout << test.input.name << ": " << (error.empty() ? "PASS" : error) << '\n';
failed += !error.empty();
}
return failed != 0;
return failed;
}

#endif



} // namespace Pokemon
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef PokemonAutomation_Pokemon_StoryStepJson_Tests_H
#define PokemonAutomation_Pokemon_StoryStepJson_Tests_H

#include <cstddef>
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
Expand All @@ -16,6 +17,12 @@ namespace Pokemon{
// Registers unit tests for the lossless shared story-data wire contract.
void add_tests_StoryStepJson(UnitTestDatabase& database);

#ifdef PA_STORY_DATA_STANDALONE
// Standalone StoryDataTests only: runs the built-in cases, prints one line
// per case, returns how many failed.
size_t run_story_step_json_cases();
#endif



} // namespace Pokemon
Expand Down
9 changes: 8 additions & 1 deletion devtools/story-data-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ set(STORY "${ROOT}/SerialPrograms/Source/Pokemon/AutoStory")
add_executable(StoryDataTests
"${STORY}/Data/Pokemon_StoryStepJson.cpp"
"${STORY}/Data/Pokemon_StoryStepJson_Tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/StoryWireCases.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/StoryDataMain.cpp"
"${ROOT}/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Direction.cpp"
"${STORY}/Pokemon_BuiltinStoryActions.cpp"
"${STORY}/Types/Pokemon_StoryActionArg.cpp"
"${STORY}/Types/Pokemon_StoryActionSpec.cpp"
Expand All @@ -25,7 +28,11 @@ add_executable(StoryDataTests
"${ROOT}/Common/Cpp/Strings/Unicode.cpp")
# Reuse the Qt/controller-free support sources; each codec has its own test main.
get_target_property(STORY_DATA_SOURCES StoryDataTests SOURCES)
list(REMOVE_ITEM STORY_DATA_SOURCES "${STORY}/Data/Pokemon_StoryStepJson_Tests.cpp")
list(REMOVE_ITEM STORY_DATA_SOURCES
"${STORY}/Data/Pokemon_StoryStepJson_Tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/StoryWireCases.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/StoryDataMain.cpp"
"${ROOT}/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Direction.cpp")
add_executable(AuthoredCheckpointTests ${STORY_DATA_SOURCES}
"${STORY}/Data/Pokemon_AuthoredCheckpointJson.cpp"
"${STORY}/Data/Pokemon_AuthoredCheckpointJson_Tests.cpp")
Expand Down
11 changes: 7 additions & 4 deletions devtools/story-data-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Run without Qt, controllers, profiles or game saves:
cmake -S devtools/story-data-tests -B build/story-data-tests
cmake --build build/story-data-tests -j4
ctest --test-dir build/story-data-tests --output-on-failure
build/story-data-tests/StoryDataTests /path/to/PokemonSimulation/data/story/wire-conformance.json
```

For a multi-configuration generator, add `--config Debug` to the build,
Expand All @@ -18,13 +19,15 @@ facing, and fills arg fallbacks. Unknown fields, kinds, actions and invalid
primitive types fail. The C++ side has no writer; its tests check the values
read.

The portable workflow checks the Python reader against the synthetic
conformance cases at
[PokemonSimulation revision 866613f](https://github.com/dayfine/PokemonSimulation/tree/866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3/data/story).
Given a path, `StoryDataTests` reads PokemonSimulation's synthetic
conformance cases (`pokesim-story-wire-cases/2`) with the native readers and
checks each accept/reject and value read (`StoryWireCases.cpp`). The portable
workflow runs it and the Python reader on the same cases at
[PokemonSimulation revision 4e023f3](https://github.com/dayfine/PokemonSimulation/tree/4e023f3d57022c68018f95f6fc0a4c0722d53adf/data/story).
This fixture revision is a contract-test dependency, not an approved
map-resource revision.

See the [shared checkpoint contract](https://github.com/dayfine/PokemonSimulation/blob/866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3/docs/story/CHECKPOINT_CONTRACT.md)
See the [shared checkpoint contract](https://github.com/dayfine/PokemonSimulation/blob/4e023f3d57022c68018f95f6fc0a4c0722d53adf/docs/story/CHECKPOINT_CONTRACT.md)
for the field boundary and proposed common requirements, state, save/retry and
handoff envelope. Both games can use those policies; their menu/detector/action
bindings remain game specific.
Expand Down
25 changes: 25 additions & 0 deletions devtools/story-data-tests/StoryDataMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Story Data Tests Main
*
* From: https://github.com/PokemonAutomation/
*
* Entry point of the standalone StoryDataTests: with no argument it runs
* the built-in story step JSON cases, with a path it checks
* PokemonSimulation's shared wire-case file.
*
*/

#include <iostream>
#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.h"
#include "StoryWireCases.h"

int main(int argc, char** argv){
using namespace PokemonAutomation::Pokemon;
if (argc == 1){
return run_story_step_json_cases() != 0;
}
if (argc == 2){
return check_story_wire_cases(argv[1]) != 0;
}
std::cerr << "Usage: StoryDataTests [wire-cases.json]" << std::endl;
return 2;
}
Loading
Loading