use ctest for testing and set testing environment for using test data

pull/69/head
Alexandra Latysheva 2020-10-30 14:52:53 +00:00
parent 64d04a80e5
commit 4bd158a68f
6 changed files with 13 additions and 30 deletions

View File

@ -38,7 +38,8 @@ output: `images/rgbtobgr_red_ball.png`
#### Tests:
You should add `-DLIBPNG_SAPI_ENABLE_TESTS=ON` to use tests and run:
You should add `-DLIBPNG_SAPI_ENABLE_TESTS=ON` to use tests and do:
```
./tests/tests
cd tests
ctest .
```

View File

@ -32,5 +32,4 @@ target_link_libraries(tests PRIVATE
sapi::sapi
)
gtest_discover_tests(tests)
gtest_discover_tests(tests PROPERTIES ENVIRONMENT "TEST_SRCDIR=${PROJECT_SOURCE_DIR}")

View File

@ -28,7 +28,7 @@ using ::testing::Eq;
using ::testing::IsTrue;
TEST(SandboxTest, ReadWrite) {
std::string infile = GetTestFilePath("pngtest.png");
std::string infile = GetFilePath("pngtest.png");
absl::StatusOr<std::string> status_or_path =
sandbox2::CreateNamedTempFileAndClose("output.png");

View File

@ -191,8 +191,8 @@ void WritePng(LibPNGApi& api, absl::string_view outfile, Data& data) {
}
TEST(SandboxTest, ReadModifyWrite) {
std::string infile = GetTestFilePath("red_ball.png");
std::string outfile = GetTestFilePath("test_output.png");
std::string infile = GetFilePath("red_ball.png");
std::string outfile = GetFilePath("test_output.png");
LibPNGSapiSandbox sandbox;
ASSERT_THAT(sandbox.Init(), IsOk());

View File

@ -13,28 +13,12 @@
// limitations under the License.
#include "helper.h" // NOLINT(build/include)
#include "../sandboxed.h" // NOLINT(build/include)
#include "sandboxed_api/sandbox2/util/fileops.h"
#include "sandboxed_api/sandbox2/util/path.h"
std::string GetImagesFolder() {
std::string cwd = sandbox2::file_util::fileops::GetCWD();
auto find = cwd.rfind("/build");
if (find == std::string::npos) {
LOG(ERROR) << "Something went wrong: CWD don't contain build dir. "
<< "Please run tests from build dir, path might be incorrect\n";
std::string GetSourcePath() { return getenv("TEST_SRCDIR"); }
return sandbox2::file::JoinPath(cwd, "images");
}
return sandbox2::file::JoinPath(cwd.substr(0, find), "images");
std::string GetFilePath(absl::string_view filename) {
return sandbox2::file::JoinPath(GetSourcePath(), "images", filename);
}
std::string GetTestFilePath(const std::string& filename) {
static std::string* images_folder_path = nullptr;
if (!images_folder_path) {
images_folder_path = new std::string(GetImagesFolder());
}
return sandbox2::file::JoinPath(*images_folder_path, filename);
}

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string>
std::string GetTestFilePath(const std::string& filename);
#include "absl/strings/str_join.h"
std::string GetFilePath(absl::string_view filename);