Skip to content

Commit 582c3f3

Browse files
committed
Update zip test
1 parent a57bea8 commit 582c3f3

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

test/zip/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_executable(
55

66
target_link_libraries(
77
zip_test
8+
scratchcpp
89
GTest::gtest_main
910
zip
1011
)

test/zip/zip_test.cpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
1-
#include <gtest/gtest.h>
2-
#include <zip.h>
3-
#include <filesystem>
1+
#include <internal/zipreader.h>
42
#include "../common.h"
53

6-
std::string readSb3Json(const std::string &fileName)
4+
using namespace libscratchcpp;
5+
6+
inline std::string readSb3Json(const std::string &fileName)
7+
{
8+
ZipReader reader(fileName);
9+
reader.open();
10+
11+
return reader.readFileToString(fileName);
12+
}
13+
14+
TEST(ZipTest, NonexistentProject)
715
{
8-
// TODO: Move this to a class and use it in Scratch3Reader
9-
// Open the zip file
10-
unsigned char *buf;
11-
size_t bufsize;
12-
struct zip_t *zip = zip_open(fileName.c_str(), 0, 'r');
13-
14-
// Extract project.json
15-
zip_entry_open(zip, "project.json");
16-
bufsize = zip_entry_size(zip);
17-
buf = (unsigned char *)calloc(sizeof(unsigned char), bufsize);
18-
zip_entry_noallocread(zip, (void *)buf, bufsize);
19-
zip_entry_close(zip);
20-
std::string str(reinterpret_cast<char const *>(buf));
21-
free(buf);
22-
23-
// Remove garbage after the JSON
24-
int end;
25-
for (end = str.size(); end >= 0; end--) {
26-
char ch = str[end];
27-
if (ch == '}') {
28-
break;
29-
}
30-
}
31-
return str.substr(0, end + 1);
16+
ASSERT_TRUE(readSb3Json("idontexist.sb3").empty());
3217
}
3318

3419
TEST(ZipTest, EmptyProject)

0 commit comments

Comments
 (0)