| 1 | /* test_file.cc - Test file functionality |
| 2 | part of the minizip-ng project |
| 3 | |
| 4 | Copyright (C) Nathan Moinvaziri |
| 5 | https://github.com/zlib-ng/minizip-ng |
| 6 | |
| 7 | This program is distributed under the terms of the same license as zlib. |
| 8 | See the accompanying LICENSE file for the full text of the license. |
| 9 | */ |
| 10 | |
| 11 | #include "mz.h" |
| 12 | #include "mz_os.h" |
| 13 | |
| 14 | #include <gtest/gtest.h> |
| 15 | #include <fstream> |
| 16 | #include <cstdio> |
| 17 | |
| 18 | TEST(os, get_file_date_ads) { |
| 19 | const std::string main_stream_name = "minizip_ads_test"; |
| 20 | const std::string ads_name = main_stream_name + ":ads"; |
| 21 | const std::string ads_contents = "Alternate Data Stream"; |
| 22 | |
| 23 | // Create main stream |
| 24 | std::ofstream main_stream(main_stream_name); |
| 25 | main_stream.close(); |
| 26 | |
| 27 | // Attach ADS |
| 28 | std::ofstream ads(ads_name); |
| 29 | ads << ads_contents; |
| 30 | ads.close(); |
| 31 | |
| 32 | // Get file date |
| 33 | time_t modified_date = 0; |
| 34 | time_t accessed_date = 0; |
| 35 | time_t creation_date = 0; |
| 36 | |
| 37 | EXPECT_EQ(MZ_OK, mz_os_get_file_date(ads_name.c_str(), &modified_date, &accessed_date, &creation_date)); |
| 38 | |
| 39 | std::remove(main_stream_name.c_str()); |
| 40 | |
| 41 | ASSERT_GT(modified_date, 0); |
| 42 | ASSERT_GT(accessed_date, 0); |
| 43 | ASSERT_GT(creation_date, 0); |
| 44 | } |