made filenames const, changed main into main_unsandboxed.

This commit is contained in:
Andrei Medar 2020-08-20 16:37:45 +00:00
parent eb2a2c023b
commit 47b519dba4
6 changed files with 16 additions and 22 deletions

View File

@ -26,8 +26,10 @@ add_library(lodepng STATIC
)
# Build SAPI library
#set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
set(SAPI_ROOT "/usr/local/google/home/amedar/internship/sandboxed-api" CACHE PATH "Path to the Sandboxed API source tree")
add_subdirectory("${SAPI_ROOT}"
"${CMAKE_BINARY_DIR}/sandboxed-api-build"
EXCLUDE_FROM_ALL

View File

@ -13,11 +13,11 @@
# limitations under the License.
# Build the unsandboxed main
add_executable(lodepng_normal
main.cc
add_executable(lodepng_unsandboxed
main_unsandboxed.cc
)
)
target_link_libraries(lodepng_normal PRIVATE
target_link_libraries(lodepng_unsandboxed PRIVATE
lodepng
)

View File

@ -19,8 +19,6 @@
#include "sandbox.h"
#include "sandboxed_api/util/flag.h"
ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all);
ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all_and_log);
ABSL_FLAG(string, images_path, std::filesystem::current_path().string(),
"path to the folder containing test images");
@ -41,8 +39,7 @@ void generate_one_step(SapiLodepngSandbox &sandbox, LodepngApi &api) {
// encode the image
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
sapi::v::UInt sapi_width(width), sapi_height(height);
std::string filename = "/output/out_generated1.png";
sapi::v::ConstCStr sapi_filename(filename.c_str());
sapi::v::ConstCStr sapi_filename("/output/out_generated1.png");
sapi::StatusOr<unsigned int> result = api.lodepng_encode32_file(
sapi_filename.PtrBefore(), sapi_image.PtrBefore(), sapi_width.GetValue(),
@ -110,8 +107,7 @@ void generate_two_steps(SapiLodepngSandbox &sandbox, LodepngApi &api) {
// encode the image into memory first
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
sapi::v::UInt sapi_width(width), sapi_height(height);
std::string filename = "/output/out_generated2.png";
sapi::v::ConstCStr sapi_filename(filename.c_str());
sapi::v::ConstCStr sapi_filename("/output/out_generated2.png");
sapi::v::ULLong sapi_pngsize;
sapi::v::IntBase<unsigned char *> sapi_png_ptr(0);
@ -197,9 +193,7 @@ void generate_two_steps(SapiLodepngSandbox &sandbox, LodepngApi &api) {
int main(int argc, char *argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
std::string images_path(absl::GetFlag(FLAGS_images_path));
SapiLodepngSandbox sandbox(images_path);
SapiLodepngSandbox sandbox(absl::GetFlag(FLAGS_images_path));
assert(sandbox.Init().ok());
LodepngApi api(&sandbox);

View File

@ -25,7 +25,7 @@ using testing::NotNull;
namespace {
// use the current path
std::string images_path = std::filesystem::current_path().string();
const std::string images_path = std::filesystem::current_path().string();
TEST(initSandbox, basic) {
SapiLodepngSandbox sandbox(images_path);
@ -56,8 +56,7 @@ TEST(generate_image, encode_decode_compare_one_step) {
// encode the image
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
sapi::v::UInt sapi_width(width), sapi_height(height);
std::string filename = "/output/out_generated1.png";
sapi::v::ConstCStr sapi_filename(filename.c_str());
sapi::v::ConstCStr sapi_filename("/output/out_generated1.png");
SAPI_ASSERT_OK_AND_ASSIGN(
unsigned int result,
@ -134,8 +133,7 @@ TEST(generate_image, encode_decode_compare_two_steps) {
// encode the image into memory first
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
sapi::v::UInt sapi_width(width), sapi_height(height);
std::string filename = "/output/out_generated2.png";
sapi::v::ConstCStr sapi_filename(filename.c_str());
sapi::v::ConstCStr sapi_filename("/output/out_generated2.png");
sapi::v::ULLong sapi_pngsize;
sapi::v::IntBase<unsigned char *> sapi_png_ptr(0);

View File

@ -33,7 +33,7 @@ void generate_one_step(const std::string &images_path) {
}
// encode the image
std::string filename = images_path + "/out_generated1.png";
const std::string filename = images_path + "/out_generated1.png";
unsigned int result =
lodepng_encode32_file(filename.c_str(), image.data(), width, height);
@ -74,7 +74,7 @@ void generate_two_steps(const std::string &images_path) {
}
// encode the image into memory first
std::string filename = images_path + "/out_generated2.png";
const std::string filename = images_path + "/out_generated2.png";
unsigned char *png;
size_t pngsize;
@ -113,7 +113,7 @@ void generate_two_steps(const std::string &images_path) {
}
int main(int argc, char *argv[]) {
std::string images_path = std::filesystem::current_path().string();
const std::string images_path = std::filesystem::current_path().string();
generate_one_step(images_path);
generate_two_steps(images_path);

View File

@ -43,7 +43,7 @@ class SapiLodepngSandbox : public LodepngSandbox {
}
private:
std::string images_path_;
const std::string images_path_;
};
#endif // SAPI_LODEPNG_SANDBOX_H_