mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
made filenames const, changed main into main_unsandboxed.
This commit is contained in:
parent
eb2a2c023b
commit
47b519dba4
|
@ -26,8 +26,10 @@ add_library(lodepng STATIC
|
||||||
)
|
)
|
||||||
|
|
||||||
# Build SAPI library
|
# 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")
|
set(SAPI_ROOT "/usr/local/google/home/amedar/internship/sandboxed-api" CACHE PATH "Path to the Sandboxed API source tree")
|
||||||
|
|
||||||
|
|
||||||
add_subdirectory("${SAPI_ROOT}"
|
add_subdirectory("${SAPI_ROOT}"
|
||||||
"${CMAKE_BINARY_DIR}/sandboxed-api-build"
|
"${CMAKE_BINARY_DIR}/sandboxed-api-build"
|
||||||
EXCLUDE_FROM_ALL
|
EXCLUDE_FROM_ALL
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Build the unsandboxed main
|
# Build the unsandboxed main
|
||||||
add_executable(lodepng_normal
|
add_executable(lodepng_unsandboxed
|
||||||
main.cc
|
main_unsandboxed.cc
|
||||||
|
)
|
||||||
|
|
||||||
)
|
target_link_libraries(lodepng_unsandboxed PRIVATE
|
||||||
target_link_libraries(lodepng_normal PRIVATE
|
|
||||||
lodepng
|
lodepng
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
#include "sandbox.h"
|
#include "sandbox.h"
|
||||||
#include "sandboxed_api/util/flag.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(),
|
ABSL_FLAG(string, images_path, std::filesystem::current_path().string(),
|
||||||
"path to the folder containing test images");
|
"path to the folder containing test images");
|
||||||
|
|
||||||
|
@ -41,8 +39,7 @@ void generate_one_step(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
||||||
// encode the image
|
// encode the image
|
||||||
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
||||||
sapi::v::UInt sapi_width(width), sapi_height(height);
|
sapi::v::UInt sapi_width(width), sapi_height(height);
|
||||||
std::string filename = "/output/out_generated1.png";
|
sapi::v::ConstCStr sapi_filename("/output/out_generated1.png");
|
||||||
sapi::v::ConstCStr sapi_filename(filename.c_str());
|
|
||||||
|
|
||||||
sapi::StatusOr<unsigned int> result = api.lodepng_encode32_file(
|
sapi::StatusOr<unsigned int> result = api.lodepng_encode32_file(
|
||||||
sapi_filename.PtrBefore(), sapi_image.PtrBefore(), sapi_width.GetValue(),
|
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
|
// encode the image into memory first
|
||||||
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
||||||
sapi::v::UInt sapi_width(width), sapi_height(height);
|
sapi::v::UInt sapi_width(width), sapi_height(height);
|
||||||
std::string filename = "/output/out_generated2.png";
|
sapi::v::ConstCStr sapi_filename("/output/out_generated2.png");
|
||||||
sapi::v::ConstCStr sapi_filename(filename.c_str());
|
|
||||||
|
|
||||||
sapi::v::ULLong sapi_pngsize;
|
sapi::v::ULLong sapi_pngsize;
|
||||||
sapi::v::IntBase<unsigned char *> sapi_png_ptr(0);
|
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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
|
||||||
std::string images_path(absl::GetFlag(FLAGS_images_path));
|
SapiLodepngSandbox sandbox(absl::GetFlag(FLAGS_images_path));
|
||||||
|
|
||||||
SapiLodepngSandbox sandbox(images_path);
|
|
||||||
assert(sandbox.Init().ok());
|
assert(sandbox.Init().ok());
|
||||||
|
|
||||||
LodepngApi api(&sandbox);
|
LodepngApi api(&sandbox);
|
||||||
|
|
|
@ -25,7 +25,7 @@ using testing::NotNull;
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// use the current path
|
// 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) {
|
TEST(initSandbox, basic) {
|
||||||
SapiLodepngSandbox sandbox(images_path);
|
SapiLodepngSandbox sandbox(images_path);
|
||||||
|
@ -56,8 +56,7 @@ TEST(generate_image, encode_decode_compare_one_step) {
|
||||||
// encode the image
|
// encode the image
|
||||||
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
||||||
sapi::v::UInt sapi_width(width), sapi_height(height);
|
sapi::v::UInt sapi_width(width), sapi_height(height);
|
||||||
std::string filename = "/output/out_generated1.png";
|
sapi::v::ConstCStr sapi_filename("/output/out_generated1.png");
|
||||||
sapi::v::ConstCStr sapi_filename(filename.c_str());
|
|
||||||
|
|
||||||
SAPI_ASSERT_OK_AND_ASSIGN(
|
SAPI_ASSERT_OK_AND_ASSIGN(
|
||||||
unsigned int result,
|
unsigned int result,
|
||||||
|
@ -134,8 +133,7 @@ TEST(generate_image, encode_decode_compare_two_steps) {
|
||||||
// encode the image into memory first
|
// encode the image into memory first
|
||||||
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
sapi::v::Array<unsigned char> sapi_image(image.data(), img_len);
|
||||||
sapi::v::UInt sapi_width(width), sapi_height(height);
|
sapi::v::UInt sapi_width(width), sapi_height(height);
|
||||||
std::string filename = "/output/out_generated2.png";
|
sapi::v::ConstCStr sapi_filename("/output/out_generated2.png");
|
||||||
sapi::v::ConstCStr sapi_filename(filename.c_str());
|
|
||||||
|
|
||||||
sapi::v::ULLong sapi_pngsize;
|
sapi::v::ULLong sapi_pngsize;
|
||||||
sapi::v::IntBase<unsigned char *> sapi_png_ptr(0);
|
sapi::v::IntBase<unsigned char *> sapi_png_ptr(0);
|
||||||
|
|
|
@ -33,7 +33,7 @@ void generate_one_step(const std::string &images_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// encode the image
|
// encode the image
|
||||||
std::string filename = images_path + "/out_generated1.png";
|
const std::string filename = images_path + "/out_generated1.png";
|
||||||
unsigned int result =
|
unsigned int result =
|
||||||
lodepng_encode32_file(filename.c_str(), image.data(), width, height);
|
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
|
// 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;
|
unsigned char *png;
|
||||||
size_t pngsize;
|
size_t pngsize;
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ void generate_two_steps(const std::string &images_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
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_one_step(images_path);
|
||||||
generate_two_steps(images_path);
|
generate_two_steps(images_path);
|
|
@ -43,7 +43,7 @@ class SapiLodepngSandbox : public LodepngSandbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string images_path_;
|
const std::string images_path_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SAPI_LODEPNG_SANDBOX_H_
|
#endif // SAPI_LODEPNG_SANDBOX_H_
|
Loading…
Reference in New Issue
Block a user