File tree Expand file tree Collapse file tree 2 files changed +14
-28
lines changed Expand file tree Collapse file tree 2 files changed +14
-28
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ add_executable(
55
66target_link_libraries (
77 zip_test
8+ scratchcpp
89 GTest::gtest_main
910 zip
1011)
Original file line number Diff line number Diff line change 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
3419TEST (ZipTest, EmptyProject)
You can’t perform that action at this time.
0 commit comments