2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file test_zip_input.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of zip input tests
23 #include <dpl/test/test_runner.h>
24 #include <dpl/zip_input.h>
25 #include <dpl/foreach.h>
26 #include <dpl/abstract_waitable_input_adapter.h>
27 #include <dpl/abstract_waitable_output_adapter.h>
28 #include <dpl/binary_queue.h>
30 #include <dpl/log/wrt_log.h>
33 const char* PATH_NO_FILE = "/opt/share/wrt/wrt-commons/tests/core/no_such_file";
34 const char* PATH_ARCHIVE = "/opt/share/wrt/wrt-commons/tests/core/sample.zip";
35 const char* ARCHIVED_FILE = "sample.txt";
38 RUNNER_TEST_GROUP_INIT(DPL)
41 Name: ZipInput_OpenFailed
42 Description: tests opening non existing file
43 Expected: exception throw
45 RUNNER_TEST(ZipInput_OpenFailed)
51 DPL::ZipInput zip(PATH_NO_FILE);
54 Catch(DPL::ZipInput::Exception::OpenFailed)
59 RUNNER_ASSERT(opened == false);
63 Name: ZipInput_OpenFile
64 Description: tests opening existing file
65 Expected: zip stats should mkatch expected
67 RUNNER_TEST(ZipInput_OpenFile)
69 DPL::ZipInput zip(PATH_ARCHIVE);
74 WrtLogD("FileInfo: ");
75 WrtLogD("name: %s", iter->name.c_str());
76 WrtLogD("comment: %s", iter->comment.c_str());
77 WrtLogD("compressedSize: %lli", iter->compressedSize);
78 WrtLogD("uncompressedSize: %lli", iter->uncompressedSize);
83 Name: ZipInput_UnzipSingleFile
84 Description: tests opening existing file and unzipping single file
85 Expected: right content
87 RUNNER_TEST(ZipInput_UnzipSingleFile)
89 DPL::ZipInput zip(PATH_ARCHIVE);
90 DPL::ZipInput::File *file = zip.OpenFile(ARCHIVED_FILE);
91 DPL::AbstractWaitableInputAdapter fileAdapter(file);
92 DPL::BinaryQueue buffer;
93 DPL::AbstractWaitableOutputAdapter bufferAdapter(&buffer);
95 DPL::Copy(&fileAdapter, &bufferAdapter);
97 std::unique_ptr<char[]> data(new char[buffer.Size() + 1]);
98 buffer.Flatten(data.get(), buffer.Size());
99 data[buffer.Size()] = '\0';
101 RUNNER_ASSERT(std::string(data.get()) == "test");