Skip to content

Commit f7ca255

Browse files
committed
Added a few more tests
1 parent fde3d45 commit f7ca255

4 files changed

Lines changed: 51 additions & 2 deletions

File tree

libpiper/src/main/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ target_sources(
2222

2323
target_link_libraries(main_utils PRIVATE piper)
2424

25-
target_link_libraries(piper_exe PRIVATE piper main_utils)
25+
target_link_libraries(piper_exe PRIVATE piper main_utils)
26+
27+
install(
28+
TARGETS piper_exe
29+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
30+
)

libpiper/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ endif()
5959

6060
include(GoogleTest)
6161
get_target_property(PIPER_BINARY_DIR piper BINARY_DIR)
62+
get_target_property(PIPER_EXE_BINARY_DIR piper_exe BINARY_DIR)
6263

6364
gtest_discover_tests(piper_test
6465
DISCOVERY_MODE PRE_TEST
65-
PROPERTIES ENVIRONMENT "PATH=${PIPER_BINARY_DIR}/$<CONFIG>;${ONNXRUNTIME_DIR}/lib;$ENV{PATH}"
66+
PROPERTIES ENVIRONMENT "PATH=${PIPER_EXE_BINARY_DIR}/$<CONFIG>;${PIPER_BINARY_DIR}/$<CONFIG>;${ONNXRUNTIME_DIR}/lib;$ENV{PATH}"
6667
)

libpiper/tests/test_main_utils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,21 @@ TEST_F(MainUtilsTest, ParseArgsMissingModel) {
108108
throw;
109109
},
110110
std::runtime_error);
111+
}
112+
113+
TEST_F(MainUtilsTest, ParseArgsMissingArgument) {
114+
piper::RunConfig runConfig;
115+
116+
const char *argv[] = {"test_program", "--model"};
117+
int argc = sizeof(argv) / sizeof(argv[0]);
118+
119+
EXPECT_THROW(
120+
try {
121+
parseArgsLogic(argc, const_cast<char **>(argv), runConfig);
122+
} catch (const piper::ArgError &e) {
123+
EXPECT_STREQ(e.what(), "Missing argument for --model");
124+
throw;
125+
},
126+
piper::ArgError
127+
);
111128
}

libpiper/tests/test_process.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ TEST_F(ProcessTest, ProcessInputStreamFileOutput) {
106106
std::filesystem::remove(outputPath);
107107
}
108108

109+
TEST_F(ProcessTest, ProcessInputStreamDirectoryOutput) {
110+
piper::RunConfig runConfig;
111+
auto outputDir = std::filesystem::temp_directory_path() / "piper_test_output";
112+
std::filesystem::create_directory(outputDir);
113+
runConfig.outputPath = outputDir;
114+
runConfig.outputType = piper::OUTPUT_DIRECTORY;
115+
116+
piper_synthesize_options options = piper_default_synthesize_options(synth);
117+
options.speaker_id = 0;
118+
119+
StdinRedirect redirect("This is a test for directory output.");
120+
121+
std::stringstream cout_buffer;
122+
std::streambuf* old_cout = std::cout.rdbuf(cout_buffer.rdbuf());
123+
124+
processInputStream(runConfig, synth, &options);
125+
126+
std::cout.rdbuf(old_cout);
127+
128+
std::string created_path = cout_buffer.str();
129+
created_path.erase(created_path.find_last_not_of(" \n\r\t")+1);
130+
ASSERT_TRUE(std::filesystem::exists(created_path));
131+
ASSERT_GT(std::filesystem::file_size(created_path), 44);
132+
std::filesystem::remove_all(outputDir);
133+
}
134+
109135
TEST_F(ProcessTest, ProcessInputStreamJson) {
110136
piper::RunConfig runConfig;
111137
runConfig.outputType = piper::OUTPUT_STDOUT;

0 commit comments

Comments
 (0)