diff --git a/oss-internship-2020/sapi_lodepng/CMakeLists.txt b/oss-internship-2020/sapi_lodepng/CMakeLists.txt index 049f278..d5ae5e3 100644 --- a/oss-internship-2020/sapi_lodepng/CMakeLists.txt +++ b/oss-internship-2020/sapi_lodepng/CMakeLists.txt @@ -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 diff --git a/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt b/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt index 0a09f10..5df00f8 100644 --- a/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt +++ b/oss-internship-2020/sapi_lodepng/examples/CMakeLists.txt @@ -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 ) diff --git a/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc b/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc index a08afcc..3b9413f 100644 --- a/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc +++ b/oss-internship-2020/sapi_lodepng/examples/main_sandboxed.cc @@ -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 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 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 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 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); diff --git a/oss-internship-2020/sapi_lodepng/examples/main_unit_test.cc b/oss-internship-2020/sapi_lodepng/examples/main_unit_test.cc index 68be057..bd71525 100644 --- a/oss-internship-2020/sapi_lodepng/examples/main_unit_test.cc +++ b/oss-internship-2020/sapi_lodepng/examples/main_unit_test.cc @@ -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 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 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 sapi_png_ptr(0); diff --git a/oss-internship-2020/sapi_lodepng/examples/main.cc b/oss-internship-2020/sapi_lodepng/examples/main_unsandboxed.cc similarity index 93% rename from oss-internship-2020/sapi_lodepng/examples/main.cc rename to oss-internship-2020/sapi_lodepng/examples/main_unsandboxed.cc index a871f43..9d0aa64 100644 --- a/oss-internship-2020/sapi_lodepng/examples/main.cc +++ b/oss-internship-2020/sapi_lodepng/examples/main_unsandboxed.cc @@ -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); diff --git a/oss-internship-2020/sapi_lodepng/examples/sandbox.h b/oss-internship-2020/sapi_lodepng/examples/sandbox.h index 6317d6d..a3658cc 100644 --- a/oss-internship-2020/sapi_lodepng/examples/sandbox.h +++ b/oss-internship-2020/sapi_lodepng/examples/sandbox.h @@ -43,7 +43,7 @@ class SapiLodepngSandbox : public LodepngSandbox { } private: - std::string images_path_; + const std::string images_path_; }; #endif // SAPI_LODEPNG_SANDBOX_H_ \ No newline at end of file