mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Fixed patch command in cmake. Fixed style
This commit is contained in:
parent
0bc5c28cb5
commit
9bc3d123a9
1
oss-internship-2020/sapi_lodepng/.gitignore
vendored
1
oss-internship-2020/sapi_lodepng/.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
build/
|
||||
.clang-format
|
||||
|
|
|
@ -20,36 +20,24 @@ set(CMAKE_CXX_STANDARD 17)
|
|||
set(CMAKE_CXX_STANDARD_REQUIRED 17)
|
||||
|
||||
# Apply the patches to the header file.
|
||||
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/patches")
|
||||
|
||||
# Move the original header to a new folder to use as target, apply the patch
|
||||
# and move it back to build the library.
|
||||
add_custom_command(
|
||||
OUTPUT "${PROJECT_BINARY_DIR}/patches/lodepng.h"
|
||||
COMMENT "Applying patch to header file."
|
||||
COMMAND cp "${PROJECT_SOURCE_DIR}/patches/header.patch" "${PROJECT_BINARY_DIR}/patches/"
|
||||
COMMAND cp "${PROJECT_SOURCE_DIR}/lodepng/lodepng.h" "${PROJECT_BINARY_DIR}/patches/"
|
||||
COMMAND cd "${PROJECT_BINARY_DIR}/patches" && patch < header.patch
|
||||
COMMAND cp "${PROJECT_BINARY_DIR}/patches/lodepng.h" "${PROJECT_SOURCE_DIR}/lodepng/"
|
||||
OUTPUT "${PROJECT_BINARY_DIR}/lodepng/lodepng.h" "${PROJECT_BINARY_DIR}/lodepng/lodepng.cpp"
|
||||
COMMENT "Applying patch to header file."
|
||||
COMMAND cp -r "${PROJECT_SOURCE_DIR}/lodepng" "${PROJECT_BINARY_DIR}/"
|
||||
COMMAND cp "${PROJECT_SOURCE_DIR}/patches/header.patch" "${PROJECT_BINARY_DIR}/lodepng/"
|
||||
COMMAND cd "${PROJECT_BINARY_DIR}/lodepng" && patch < header.patch
|
||||
)
|
||||
|
||||
set_property(
|
||||
SOURCE
|
||||
"${PROJECT_SOURCE_DIR}/lodepng/lodepng.h"
|
||||
APPEND PROPERTY OBJECT_DEPENDS
|
||||
"${PROJECT_BINARY_DIR}/patches/lodepng.h"
|
||||
)
|
||||
|
||||
|
||||
# Build static library.
|
||||
add_library(lodepng STATIC
|
||||
"${PROJECT_SOURCE_DIR}/lodepng/lodepng.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/lodepng/lodepng.h"
|
||||
"${PROJECT_BINARY_DIR}/lodepng/lodepng.cpp"
|
||||
"${PROJECT_BINARY_DIR}/lodepng/lodepng.h"
|
||||
)
|
||||
|
||||
# Build SAPI library
|
||||
set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
|
||||
target_include_directories(lodepng PUBLIC "${PROJECT_BINARY_DIR}/lodepng")
|
||||
|
||||
# Build SAPI library
|
||||
set(SAPI_ROOT "${PROJECT_SOURCE_DIR}/../.." CACHE PATH "Path to the Sandboxed API source tree")
|
||||
|
||||
add_subdirectory("${SAPI_ROOT}"
|
||||
"${CMAKE_BINARY_DIR}/sandboxed-api-build"
|
||||
|
@ -58,7 +46,7 @@ add_subdirectory("${SAPI_ROOT}"
|
|||
|
||||
add_sapi_library(
|
||||
lodepng_sapi
|
||||
|
||||
|
||||
FUNCTIONS
|
||||
lodepng_decode_memory
|
||||
lodepng_decode32
|
||||
|
@ -78,8 +66,8 @@ add_sapi_library(
|
|||
|
||||
lodepng_save_file
|
||||
lodepng_load_file
|
||||
|
||||
INPUTS "${PROJECT_SOURCE_DIR}/lodepng/lodepng.h"
|
||||
|
||||
INPUTS "${PROJECT_BINARY_DIR}/lodepng/lodepng.h"
|
||||
LIBRARY lodepng
|
||||
LIBRARY_NAME Lodepng
|
||||
NAMESPACE ""
|
||||
|
|
|
@ -26,7 +26,7 @@ std::vector<uint8_t> GenerateValues() {
|
|||
image.push_back(255);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
@ -39,3 +39,4 @@ std::string CreateTempDirAtCWD() {
|
|||
CHECK(result.ok()) << "Could not create temporary directory";
|
||||
return result.value();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
||||
#include "sandboxed_api/sandbox2/util/temp_file.h"
|
||||
|
||||
constexpr size_t kWidth = 512;
|
||||
constexpr size_t kHeight = 512;
|
||||
constexpr size_t kImgLen = kWidth * kHeight * 4;
|
||||
inline constexpr size_t kWidth = 512;
|
||||
inline constexpr size_t kHeight = 512;
|
||||
inline constexpr size_t kImgLen = kWidth * kHeight * 4;
|
||||
|
||||
// Returns a vector that contains values used for testing.
|
||||
// This part of code is taken from
|
||||
|
@ -37,3 +37,4 @@ std::vector<uint8_t> GenerateValues();
|
|||
std::string CreateTempDirAtCWD();
|
||||
|
||||
#endif // SAPI_LODEPNG_HELPERS_H
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "helpers.h"
|
||||
#include "sandbox.h"
|
||||
|
||||
void EncodeDecodeOneStep(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
||||
void EncodeDecodeOneStep(SapiLodepngSandbox& sandbox, LodepngApi& api) {
|
||||
// Generate the values.
|
||||
std::vector<uint8_t> image = GenerateValues();
|
||||
|
||||
|
@ -39,7 +39,7 @@ void EncodeDecodeOneStep(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
|||
// After the image has been encoded, decode it to check that the
|
||||
// pixel values are the same.
|
||||
sapi::v::UInt sapi_width, sapi_height;
|
||||
sapi::v::IntBase<uint8_t *> sapi_image_ptr(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_image_ptr(0);
|
||||
|
||||
result = api.lodepng_decode32_file(
|
||||
sapi_image_ptr.PtrBoth(), sapi_width.PtrBoth(), sapi_height.PtrBoth(),
|
||||
|
@ -75,7 +75,7 @@ void EncodeDecodeOneStep(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
|||
<< "Could not free memory inside sandboxed process";
|
||||
}
|
||||
|
||||
void EncodeDecodeTwoSteps(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
||||
void EncodeDecodeTwoSteps(SapiLodepngSandbox& sandbox, LodepngApi& api) {
|
||||
// Generate the values.
|
||||
std::vector<uint8_t> image = GenerateValues();
|
||||
|
||||
|
@ -87,7 +87,7 @@ void EncodeDecodeTwoSteps(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
|||
sapi::v::ConstCStr sapi_filename("/output/out_generated2.png");
|
||||
|
||||
sapi::v::ULLong sapi_pngsize;
|
||||
sapi::v::IntBase<uint8_t *> sapi_png_ptr(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_png_ptr(0);
|
||||
|
||||
// Encode it into memory.
|
||||
sapi::StatusOr<unsigned int> result =
|
||||
|
@ -116,7 +116,7 @@ void EncodeDecodeTwoSteps(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
|||
|
||||
// Now, decode the image using the 2 steps in order to compare the values.
|
||||
sapi::v::UInt sapi_width, sapi_height;
|
||||
sapi::v::IntBase<uint8_t *> sapi_png_ptr2(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_png_ptr2(0);
|
||||
sapi::v::ULLong sapi_pngsize2;
|
||||
|
||||
// Load the file in memory.
|
||||
|
@ -139,7 +139,7 @@ void EncodeDecodeTwoSteps(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
|||
|
||||
// After the file is loaded, decode it so we have access to the values
|
||||
// directly.
|
||||
sapi::v::IntBase<uint8_t *> sapi_png_ptr3(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_png_ptr3(0);
|
||||
result = api.lodepng_decode32(
|
||||
sapi_png_ptr3.PtrBoth(), sapi_width.PtrBoth(), sapi_height.PtrBoth(),
|
||||
sapi_png_array2.PtrBefore(), sapi_pngsize2.GetValue());
|
||||
|
@ -171,7 +171,7 @@ void EncodeDecodeTwoSteps(SapiLodepngSandbox &sandbox, LodepngApi &api) {
|
|||
<< "Could not free memory inside sandboxed process";
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
|
||||
const std::string images_path = CreateTempDirAtCWD();
|
||||
|
@ -192,3 +192,4 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ TEST(LodePngTest, EncodeDecodeOneStep) {
|
|||
ASSERT_THAT(result, Eq(0)) << "Unexpected result from encode32_file call";
|
||||
|
||||
sapi::v::UInt sapi_width, sapi_height;
|
||||
sapi::v::IntBase<uint8_t *> sapi_image_ptr(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_image_ptr(0);
|
||||
|
||||
SAPI_ASSERT_OK_AND_ASSIGN(
|
||||
result, api.lodepng_decode32_file(
|
||||
|
@ -136,7 +136,7 @@ TEST(LodePngTest, EncodeDecodeTwoSteps) {
|
|||
sapi::v::ConstCStr sapi_filename("/output/out_generated2.png");
|
||||
|
||||
sapi::v::ULLong sapi_pngsize;
|
||||
sapi::v::IntBase<uint8_t *> sapi_png_ptr(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_png_ptr(0);
|
||||
|
||||
SAPI_ASSERT_OK_AND_ASSIGN(
|
||||
unsigned int result,
|
||||
|
@ -159,7 +159,7 @@ TEST(LodePngTest, EncodeDecodeTwoSteps) {
|
|||
ASSERT_THAT(result, Eq(0)) << "Unexpected result from save_file call";
|
||||
|
||||
sapi::v::UInt sapi_width, sapi_height;
|
||||
sapi::v::IntBase<uint8_t *> sapi_png_ptr2(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_png_ptr2(0);
|
||||
sapi::v::ULLong sapi_pngsize2;
|
||||
|
||||
SAPI_ASSERT_OK_AND_ASSIGN(
|
||||
|
@ -178,7 +178,7 @@ TEST(LodePngTest, EncodeDecodeTwoSteps) {
|
|||
ASSERT_THAT(sandbox.TransferFromSandboxee(&sapi_png_array2), IsOk())
|
||||
<< "Error during transfer from sandboxee";
|
||||
|
||||
sapi::v::IntBase<uint8_t *> sapi_png_ptr3(0);
|
||||
sapi::v::IntBase<uint8_t*> sapi_png_ptr3(0);
|
||||
SAPI_ASSERT_OK_AND_ASSIGN(
|
||||
result,
|
||||
api.lodepng_decode32(sapi_png_ptr3.PtrBoth(), sapi_width.PtrBoth(),
|
||||
|
@ -211,3 +211,4 @@ TEST(LodePngTest, EncodeDecodeTwoSteps) {
|
|||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "../lodepng/lodepng.h"
|
||||
#include "helpers.h"
|
||||
#include "lodepng.h"
|
||||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
||||
|
||||
void EncodeDecodeOneStep(const std::string &images_path) {
|
||||
void EncodeDecodeOneStep(const std::string& images_path) {
|
||||
// Generate the values.
|
||||
std::vector<uint8_t> image = GenerateValues();
|
||||
|
||||
|
@ -34,7 +34,7 @@ void EncodeDecodeOneStep(const std::string &images_path) {
|
|||
// After the image has been encoded, decode it to check that the
|
||||
// pixel values are the same.
|
||||
unsigned int width, height;
|
||||
uint8_t *image2 = 0;
|
||||
uint8_t* image2 = 0;
|
||||
|
||||
result = lodepng_decode32_file(&image2, &width, &height, filename.c_str());
|
||||
|
||||
|
@ -50,13 +50,13 @@ void EncodeDecodeOneStep(const std::string &images_path) {
|
|||
free(image2);
|
||||
}
|
||||
|
||||
void EncodeDecodeTwoSteps(const std::string &images_path) {
|
||||
void EncodeDecodeTwoSteps(const std::string& images_path) {
|
||||
// Generate the values.
|
||||
std::vector<uint8_t> image = GenerateValues();
|
||||
|
||||
// Encode the image into memory first.
|
||||
const std::string filename = images_path + "/out_generated2.png";
|
||||
uint8_t *png;
|
||||
uint8_t* png;
|
||||
size_t pngsize;
|
||||
|
||||
unsigned int result =
|
||||
|
@ -71,7 +71,7 @@ void EncodeDecodeTwoSteps(const std::string &images_path) {
|
|||
|
||||
// Now, decode the image using the 2 steps in order to compare the values.
|
||||
unsigned int width, height;
|
||||
uint8_t *png2;
|
||||
uint8_t* png2;
|
||||
size_t pngsize2;
|
||||
|
||||
// Load the file in memory.
|
||||
|
@ -80,7 +80,7 @@ void EncodeDecodeTwoSteps(const std::string &images_path) {
|
|||
CHECK(!result) << "Unexpected result from load_file call";
|
||||
CHECK(pngsize == pngsize2) << "Png sizes differ";
|
||||
|
||||
uint8_t *image2;
|
||||
uint8_t* image2;
|
||||
result = lodepng_decode32(&image2, &width, &height, png2, pngsize2);
|
||||
|
||||
CHECK(!result) << "Unexpected result from decode32 call";
|
||||
|
@ -96,7 +96,7 @@ void EncodeDecodeTwoSteps(const std::string &images_path) {
|
|||
free(image2);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
|
||||
const std::string images_path = CreateTempDirAtCWD();
|
||||
|
@ -112,3 +112,4 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,3 +47,4 @@ class SapiLodepngSandbox : public LodepngSandbox {
|
|||
};
|
||||
|
||||
#endif // SAPI_LODEPNG_SANDBOX_H_
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user