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
22 #include <dpl/test/test_runner.h>
23 #include <dpl/zip_input.h>
24 #include <dpl/foreach.h>
25 #include <dpl/abstract_waitable_input_adapter.h>
26 #include <dpl/abstract_waitable_output_adapter.h>
27 #include <dpl/binary_queue.h>
28 #include <dpl/scoped_array.h>
30 #include <dpl/log/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)
40 RUNNER_TEST(ZipInput_OpenFailed)
46 DPL::ZipInput zip(PATH_NO_FILE);
49 Catch(DPL::ZipInput::Exception::OpenFailed)
54 RUNNER_ASSERT(opened == false);
57 RUNNER_TEST(ZipInput_OpenFile)
59 DPL::ZipInput zip(PATH_ARCHIVE);
63 LogDebug("---------");
64 LogDebug("FileInfo: ");
65 #define FIELD(X) LogDebug(#X ": " << iter->X)
68 FIELD(compressedSize);
69 FIELD(uncompressedSize);
74 RUNNER_TEST(ZipInput_UnzipSingleFile)
76 DPL::ZipInput zip(PATH_ARCHIVE);
77 DPL::ZipInput::File *file = zip.OpenFile(ARCHIVED_FILE);
78 DPL::AbstractWaitableInputAdapter fileAdapter(file);
79 DPL::BinaryQueue buffer;
80 DPL::AbstractWaitableOutputAdapter bufferAdapter(&buffer);
82 DPL::Copy(&fileAdapter, &bufferAdapter);
84 DPL::ScopedArray<char> data(new char[buffer.Size() + 1]);
85 buffer.Flatten(data.Get(), buffer.Size());
86 data[buffer.Size()] = '\0';
88 RUNNER_ASSERT(std::string(data.Get()) == "test");