Browse Source

Simplified for backwards compatibility purposes

master
suhrke 5 years ago
parent
commit
1f8a8426ac
  1. 3
      .gitmodules
  2. 171
      src/FileAttributes.cpp
  3. 181
      src/FileAttributes.hpp
  4. 1
      test/Catch
  5. 275
      test/test.cpp

3
.gitmodules vendored

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
[submodule "test/Catch"]
path = test/Catch
url = https://github.com/philsquared/Catch.git

171
src/FileAttributes.cpp

@ -3,22 +3,18 @@ @@ -3,22 +3,18 @@
*
* Filename: FileAttributes.cpp
*
* Description: OS-agnostic, immutable file attribute storage created from stat
* struct or from data from roughly equivalent Windows types
* Description: OS-agnostic file attribute storage and conversion functions
*
* Version: 1.0
* Version: 2.0
* Created: 08/01/2017 09:56:21 AM
* Revision: none
* Compiler: gcc
*
* Author: suhrke@teknik.io
* Author: surkeh@protonmail.com
*
* =====================================================================================
*/
#include <iostream>
#include <ctime>
#include <sstream>
#include "FileAttributes.hpp"
@ -35,10 +31,9 @@ @@ -35,10 +31,9 @@
bool
FileAttributes::isPosixTime(time_t t)
{
const time_t EPOCH = 0;
time_t now;
time(&now);
return (t > EPOCH && t <= now);
return (t > UNIX_EPOCH && t <= now);
}
@ -68,151 +63,31 @@ FileAttributes::convertToFileTime (time_t posixTime) @@ -68,151 +63,31 @@ FileAttributes::convertToFileTime (time_t posixTime)
/*-----------------------------------------------------------------------------
* PUBLIC
*-----------------------------------------------------------------------------*/
// Construct from Windows types (typecast to portable versions)
FileAttributes::FileAttributes (FileTimePortable accessed,
FileTimePortable modified,
FileTimePortable created,
uint32_t size,
uint32_t attributes
) {
ctime_ = convertToPosixTime (created);
atime_ = convertToPosixTime (accessed);
mtime_ = convertToPosixTime (modified);
//preserve value through unsigned to signed type
std::stringstream ss;
ss << size;
ss >> size_;
mode_ = getMode (attributes);
windowsAttributes_ = attributes;
hasWindowsAttributes_ = true;
uid_ = UID_USER;
gid_ = GID_USER;
}
FileAttributes::FileAttributes (const uint32_t &mode,
const int16_t &uid,
const int16_t &gid,
const int64_t &size,
const time_t &atime,
const time_t &mtime,
const time_t &ctime
) {
mode_ = mode;
uid_ = uid;
gid_ = gid;
size_ = size;
atime_ = atime;
mtime_ = mtime;
ctime_ = ctime;
windowsAttributes_ = 0;
hasWindowsAttributes_ = false;
}
uint32_t
FileAttributes::getWindowsAttributes()
{
uint32_t windowsAttributes = 0;
if (hasWindowsAttributes_) {
windowsAttributes = windowsAttributes_;
}
else {
uint32_t readAccess =
mode_ & ( POSIX_RUSR | POSIX_RGRP | POSIX_ROTH );
uint32_t writeAccess =
mode_ & ( POSIX_WUSR | POSIX_WGRP | POSIX_WOTH );
uint32_t executeAccess =
mode_ & ( POSIX_XUSR | POSIX_XGRP | POSIX_XOTH );
if (readAccess != 0 && writeAccess == 0 && executeAccess == 0) {
windowsAttributes = WIN_READONLY;
}
else {
windowsAttributes = WIN_NORMAL;
}
}
return windowsAttributes;
}
FileTimePortable
FileAttributes::getCreatedTime()
{
return convertToFileTime(ctime_);
}
FileTimePortable
FileAttributes::getAccessedTime()
uint32_t
FileAttributes::convertToWindowsAttributes(uint32_t posixMode)
{
return convertToFileTime(atime_);
using namespace std;
uint32_t readAccess =
posixMode & ( POSIX_RUSR | POSIX_RGRP | POSIX_ROTH );
uint32_t writeAccess =
posixMode & ( POSIX_WUSR | POSIX_WGRP | POSIX_WOTH );
uint32_t executeAccess =
posixMode & ( POSIX_XUSR | POSIX_XGRP | POSIX_XOTH );
if (readAccess != 0 && writeAccess == 0 && executeAccess == 0)
return WIN_READONLY;
else
return WIN_NORMAL;
}
FileTimePortable
FileAttributes::getModifiedTime()
{
return convertToFileTime(mtime_);
}
// Get Posix File Attributes (returns by ref)
// The missing attributes should be grabbed through syscalls
void
FileAttributes::getStat (uint32_t &mode,
int16_t &uid,
int16_t &gid,
int64_t &size,
time_t &atime,
time_t &mtime,
time_t &ctime
) {
mode = mode_;
uid = uid_;
gid = gid_;
size = size_;
atime = atime_;
mtime = mtime_;
ctime = ctime_;
}
/*-----------------------------------------------------------------------------
* PRIVATE
*-----------------------------------------------------------------------------*/
uint32_t
FileAttributes::getMode (uint32_t windowsFileAttributes)
FileAttributes::convertToPosixAttributes(uint32_t windowsAttributes)
{
uint32_t readAll = POSIX_RUSR | POSIX_RGRP | POSIX_ROTH;
uint32_t executeAll = POSIX_XUSR | POSIX_XGRP | POSIX_XOTH;
uint32_t mode = 0; //bitvector
if ( windowsFileAttributes & WIN_READONLY ) {
mode |= readAll;
}
else {
// 755
mode |= readAll | executeAll | POSIX_WUSR;
}
return mode;
if (windowsAttributes & WIN_READONLY)
return POSIX_READONLY;
else
return POSIX_NORMAL;
}

181
src/FileAttributes.hpp

@ -3,73 +3,24 @@ @@ -3,73 +3,24 @@
*
* Filename: FileAttributes.h
*
* Description: OS-agnostic, immutable file attribute storage created from stat
* struct or from data from Windows GetFileAttributes
* Description: OS-agnostic file attribute storage and conversion functions
*
* Version: 1.0
* Version: 2.0
* Created: 08/01/2017 08:53:17 AM
* Revision: none
* Compiler: gcc
*
* Author: suhrke@teknik.io
* Author: surkeh@protonmail.com
*
* =====================================================================================
*/
#ifndef PORTLIBCPP_FILE_ATTRIBUTES_HPP
#define PORTLIBCPP_FILE_ATTRIBUTES_HPP
#include <cstdint>
#include <ctime>
#define UID_USER 1000 // also often 100
#define UID_ROOT 0
#define GID_USER 1000 // also often 100
#define GID_ROOT 0
#define WINDOWS_TICK 10000000
#define SEC_TO_UNIX_EPOCH 11644473600LL
// Windows File Attributes (Bit Flags)
#define WIN_READONLY 1
#define WIN_HIDDEN 2 //by file name in *NIX
#define WIN_DIRECTORY 16
#define WIN_ARCHIVE 32
#define WIN_DEVICE 64 //reserved, bit should remain unset
#define WIN_NORMAL 128 //only valid when bit is only one set
#define WIN_COMPRESSED 2048
#define WIN_SYSTEM 4 //unused
#define WIN_TEMPORARY 256 //unused
#define WIN_SPARSE_FILE 512 //unused
#define WIN_REPARSE_POINT 1024 //unused
#define WIN_OFFLINE 4096 //unused
#define WIN_NOT_INDEXED 8192 //unused
#define WIN_INTEGRITY_STREAM 32768 //unused
#define WIN_VIRTUAL 65536 //unused
#define WIN_NO_SCRUB 131072 //unused
#define WIN_RECALL_ON_OPEN 262144 //unused
#define WIN_RECALL_ON_DATA_ACCESS 4194304 //unused
#define POSIX_RWXU 0x0000700
#define POSIX_RUSR 0x0000400
#define POSIX_WUSR 0x0000200
#define POSIX_XUSR 0x0000100
#define POSIX_RWXG 0x0000070
#define POSIX_RGRP 0x0000040
#define POSIX_WGRP 0x0000020
#define POSIX_XGRP 0x0000010
#define POSIX_RWXO 0x0000007
#define POSIX_ROTH 0x0000004
#define POSIX_WOTH 0x0000002
#define POSIX_XOTH 0x0000001
#define POSIX_SGID 0x0004000
#define POSIX_SUID 0x0002000
#define POSIX_SVTX 0x0001000
typedef struct FileTimePortable {
@ -81,12 +32,11 @@ typedef struct FileTimePortable { @@ -81,12 +32,11 @@ typedef struct FileTimePortable {
class FileAttributes
{
public:
/*
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: isPosixTime
* Description: (Static utility function)
* Check if a 64-bit value is in a range of possible time_t values
* Description: Check if a 64-bit value is in a range of possible time_t values
*--------------------------------------------------------------------------------------
*/
static bool isPosixTime(time_t t);
@ -94,7 +44,7 @@ class FileAttributes @@ -94,7 +44,7 @@ class FileAttributes
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: convertToPosixTime
* Description: (Static utility function) Convert FILETIME to time_t)
* Description: Convert FILETIME to time_t
*--------------------------------------------------------------------------------------
*/
static time_t convertToPosixTime (FileTimePortable windowsTime);
@ -102,116 +52,49 @@ class FileAttributes @@ -102,116 +52,49 @@ class FileAttributes
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: convertToFileTime
* Description: (Static utility function) Convert time_t to FILETIME
* Description: Convert time_t to FILETIME
*--------------------------------------------------------------------------------------
*/
static FileTimePortable convertToFileTime (time_t posixTime);
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: Windows data constructor
* Description: Construct FileAttributes from FILETIME structs and a
* 32-bit attribute bitvector
* Note: should typecast each FILETIME to FileTimePortable and
* primitive types as necessary
*
*--------------------------------------------------------------------------------------
*/
FileAttributes (FileTimePortable accessed,
FileTimePortable modified,
FileTimePortable created,
uint32_t size,
uint32_t attributes);
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: Posix stat constructor
* Description: Construct FileAttributes from data from a stat struct
* Note: Type sizes in stat can vary. FileAttributes stores
* data such that the largest possible type from stat fits.
* Typecast as necessary.
*
*--------------------------------------------------------------------------------------
*/
FileAttributes (const uint32_t &mode,
const int16_t &uid,
const int16_t &gid,
const int64_t &size,
const time_t &atime,
const time_t &mtime,
const time_t &ctime);
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: getWindowsAttributes
* Description: Get bitvector containing file attributes
* Returns: uint32_t, attributes, guaranteed to be a 32-bit type
*--------------------------------------------------------------------------------------
*/
uint32_t getWindowsAttributes();
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: getCreatedTime
* Description: Get the Windows-compatible time the file was created
* Method: FileAttributes :: convertToWindowsAttributes
* Description: Convert mode_t into Windows attributes type
* Returns: uint32_t, Windows attributes bitvector
*--------------------------------------------------------------------------------------
*/
FileTimePortable getCreatedTime();
static uint32_t convertToWindowsAttributes(uint32_t posixMode);
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: getAccessedTime
* Description: Get the Window-compatible time the file was accessed
* Method: FileAttributes :: convertToPosixAttributes
* Description: Converts Windows attributes type into mode_t
* Returns: uint32_t, mode_t bitvector
*--------------------------------------------------------------------------------------
*/
FileTimePortable getAccessedTime();
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: getModifiedTime
* Description: Get the Window-compatible time the file was modified
*--------------------------------------------------------------------------------------
*/
FileTimePortable getModifiedTime();
// Get Posix File Attributes (returns by ref)
// The missing attributes should be grabbed through syscalls
/*
*--------------------------------------------------------------------------------------
* Class: FileAttributes
* Method: FileAttributes :: getStat
* Description: Get the POSIX-compatible stat struct data
* Parameters: Various values returned by reference
* Note: If FileAttributes was created with Windows data, mode
* will be 0755 if WIN_NORMAL or 0111 if WIN_READONLY,
* and uid and gid will be set to 0
*--------------------------------------------------------------------------------------
*/
void getStat (uint32_t &mode,
int16_t &uid,
int16_t &gid,
int64_t &size,
time_t &atime,
time_t &mtime,
time_t &ctime);
static uint32_t convertToPosixAttributes(uint32_t windowsAttributes);
private:
// Convert Windows file attributes as closely as possible
uint32_t getMode (uint32_t windowsFileAttributes);
static const long WINDOWS_TICK = 10000000;
static const long long SEC_TO_UNIX_EPOCH = 11644473600;
static const int UNIX_EPOCH = 0; //approximately
static const unsigned int WIN_READONLY = 1;
static const unsigned int WIN_NORMAL = 128;
static const unsigned int POSIX_RUSR = 0x0000400;
static const unsigned int POSIX_RGRP = 0x0000040;
static const unsigned int POSIX_ROTH = 0x0000004;
static const unsigned int POSIX_WUSR = 0x0000200;
static const unsigned int POSIX_WGRP = 0x0000020;
static const unsigned int POSIX_WOTH = 0x0000002;
static const unsigned int POSIX_XUSR = 0x0000100;
static const unsigned int POSIX_XGRP = 0x0000010;
static const unsigned int POSIX_XOTH = 0x0000001;
static const unsigned int POSIX_READONLY = 0x0000444;
static const unsigned int POSIX_NORMAL = 0x0000755;
uint32_t mode_;
int16_t uid_;
int16_t gid_;
int64_t size_;
time_t atime_;
time_t mtime_;
time_t ctime_;
// May contain additional flags not used by POSIX
uint32_t windowsAttributes_;
bool hasWindowsAttributes_;
};

1
test/Catch

@ -1 +0,0 @@ @@ -1 +0,0 @@
Subproject commit ec2074e55808d83117f70c633eb9ae47b433dd0d

275
test/test.cpp

@ -39,9 +39,53 @@ BOOST_AUTO_TEST_SUITE (All) @@ -39,9 +39,53 @@ BOOST_AUTO_TEST_SUITE (All)
#define UID_USER 1000 // also often 100
#define UID_ROOT 0
#define GID_USER 1000 // also often 100
#define GID_ROOT 0
// Windows File Attributes (Bit Flags)
#define WIN_READONLY 1
#define WIN_HIDDEN 2 //by file name in *NIX
#define WIN_DIRECTORY 16
#define WIN_ARCHIVE 32
#define WIN_DEVICE 64 //reserved, bit should remain unset
#define WIN_NORMAL 128 //only valid when bit is only one set
#define WIN_COMPRESSED 2048
#define WIN_SYSTEM 4 //unused
#define WIN_TEMPORARY 256 //unused
#define WIN_SPARSE_FILE 512 //unused
#define WIN_REPARSE_POINT 1024 //unused
#define WIN_OFFLINE 4096 //unused
#define WIN_NOT_INDEXED 8192 //unused
#define WIN_INTEGRITY_STREAM 32768 //unused
#define WIN_VIRTUAL 65536 //unused
#define WIN_NO_SCRUB 131072 //unused
#define WIN_RECALL_ON_OPEN 262144 //unused
#define WIN_RECALL_ON_DATA_ACCESS 4194304 //unused
#define POSIX_RWXU 0x0000700
#define POSIX_RUSR 0x0000400
#define POSIX_WUSR 0x0000200
#define POSIX_XUSR 0x0000100
#define POSIX_RWXG 0x0000070
#define POSIX_RGRP 0x0000040
#define POSIX_WGRP 0x0000020
#define POSIX_XGRP 0x0000010
#define POSIX_RWXO 0x0000007
#define POSIX_ROTH 0x0000004
#define POSIX_WOTH 0x0000002
#define POSIX_XOTH 0x0000001
#define POSIX_SGID 0x0004000
#define POSIX_SUID 0x0002000
#define POSIX_SVTX 0x0001000
BOOST_AUTO_TEST_CASE (StaticPosixTimeCheckFunction)
BOOST_AUTO_TEST_CASE (IsPosixTimeCheckFunction)
{
//BOOST_TEST_MESSAGE("isPosixTime accepts time_t");
BOOST_CHECK (FileAttributes::isPosixTime (static_cast<time_t>(ATIME)) == true);
@ -49,218 +93,85 @@ BOOST_AUTO_TEST_CASE (StaticPosixTimeCheckFunction) @@ -49,218 +93,85 @@ BOOST_AUTO_TEST_CASE (StaticPosixTimeCheckFunction)
int64_t ft = HIGH_A;
ft = ft << 32;
ft |= LOW_A;
BOOST_CHECK (FileAttributes::isPosixTime (ft) == false);
BOOST_CHECK (FileAttributes::isPosixTime(ft) == false);
}
BOOST_AUTO_TEST_CASE (NoPrecisionLoss)
BOOST_AUTO_TEST_CASE (ConvertFILETIMEToTimeT)
{
// Mock up data
FileTimePortable c;
c.dwLowDateTime = LOW_C;
c.dwHighDateTime = HIGH_C;
uint32_t attr = WIN_NORMAL;
uint32_t sz = 12341234;
// create variables
uint32_t mode;
int16_t user;
int16_t group;
int64_t size;
time_t atime;
time_t mtime;
time_t ctime;
// Mock up FILETIME struct data
FileTimePortable m;
m.dwLowDateTime = LOW_M;
m.dwHighDateTime = HIGH_M;
// convert several times
for( int i = 0; i < 10; i++ ) {
FileAttributes fa(c, c, c, sz, attr);
fa.getStat(mode, user, group, size, atime, mtime, ctime);
FileAttributes fa2(mode, user, group, size, atime, mtime, ctime);
c = fa2.getCreatedTime();
}
//BOOST_TEST_MESSAGE(mtime);
BOOST_CHECK (FileAttributes::convertToPosixTime(m) == MTIME);
}
BOOST_CHECK (c.dwLowDateTime == LOW_C);
BOOST_CHECK (c.dwHighDateTime == HIGH_C);
BOOST_AUTO_TEST_CASE (ConvertTimeTToFILETIME)
{
time_t tt = ATIME;
FileTimePortable conv = FileAttributes::convertToFileTime(tt);
BOOST_CHECK (conv.dwLowDateTime == LOW_A);
BOOST_CHECK (conv.dwHighDateTime == HIGH_A);
}
BOOST_AUTO_TEST_CASE (ConstructsFromWindowsData )
BOOST_AUTO_TEST_CASE (ConvertWindowsFileAttributesToPosixMode)
{
// Mock up FILETIME struct data
FileTimePortable a;
a.dwLowDateTime = LOW_A;
a.dwHighDateTime = HIGH_A;
FileTimePortable m;
m.dwLowDateTime = LOW_M;
m.dwHighDateTime = HIGH_M;
FileTimePortable c;
c.dwLowDateTime = LOW_C;
c.dwHighDateTime = HIGH_C;
// Mock up other data
uint32_t attr = WIN_NORMAL;
uint32_t sz = 12341234;
// Instantiate object
FileAttributes fa(a, m, c, sz, attr);
//BOOST_TEST_MESSAGE ("Gets stat data");
{
uint32_t mode;
int16_t uid;
int16_t gid;
int64_t size;
time_t atime;
time_t mtime;
time_t ctime;
fa.getStat(mode, uid, gid, size, atime, mtime, ctime);
//BOOST_TEST_MESSAGE ("Mode converted as closely as possible");
{
BOOST_CHECK (mode == 0x00000755);
}
//BOOST_TEST_MESSAGE ("Default values are used for uid and gid");
{
BOOST_CHECK (uid == UID_USER);
BOOST_CHECK (gid == GID_USER);
}
//BOOST_TEST_MESSAGE ("Size converts despite differently-signed types");
{
BOOST_CHECK (size == 12341234);
}
//BOOST_TEST_MESSAGE ("Gets time_t");
{
//BOOST_TEST_MESSAGE(ctime);
BOOST_CHECK (ctime == CTIME);
//BOOST_TEST_MESSAGE(atime);
BOOST_CHECK (atime == ATIME);
//BOOST_TEST_MESSAGE(mtime);
BOOST_CHECK (mtime == MTIME);
}
}
//BOOST_TEST_MESSAGE ("Gets Windows FILETIME");
{
FileTimePortable accessed = fa.getAccessedTime();
//BOOST_TEST_MESSAGE(accessed.dwLowDateTime);
BOOST_CHECK (accessed.dwLowDateTime == LOW_A);
//BOOST_TEST_MESSAGE(accessed.dwHighDateTime);
BOOST_CHECK (accessed.dwHighDateTime == HIGH_A);
FileTimePortable modified = fa.getModifiedTime();
//BOOST_TEST_MESSAGE(modified.dwLowDateTime);
BOOST_CHECK (modified.dwLowDateTime == LOW_M);
//BOOST_TEST_MESSAGE(modified.dwHighDateTime);
BOOST_CHECK (modified.dwHighDateTime == HIGH_M);
FileTimePortable created = fa.getCreatedTime();
//BOOST_TEST_MESSAGE(created.dwLowDateTime);
BOOST_CHECK (created.dwLowDateTime == LOW_C);
//BOOST_TEST_MESSAGE(created.dwHighDateTime);
BOOST_CHECK (created.dwHighDateTime == HIGH_C);
}
//BOOST_TEST_MESSAGE ("All Windows file attribute data is preserved in Win-Win");
{
BOOST_CHECK (fa.getWindowsAttributes() == WIN_NORMAL);
}
//BOOST_TEST_MESSAGE ("Mode converted as closely as possible");
BOOST_CHECK (FileAttributes::convertToPosixAttributes(attr) == 0x00000755);
}
BOOST_AUTO_TEST_CASE (ConvertPosixModeToWindowsFileAttributes)
{
uint32_t mode = 0x00000743;
//BOOST_TEST_MESSAGE ("Mode converted as closely as possible");
BOOST_CHECK (FileAttributes::convertToWindowsAttributes(mode) == WIN_NORMAL);
}
BOOST_AUTO_TEST_CASE (ReadonlyTranslatesFromWindowsToLinux)
{
// Mock up FILETIME struct data (we dont care about what these are here)
FileTimePortable a;
FileTimePortable m;
FileTimePortable c;
// Mock up other data
uint32_t attr = WIN_READONLY;
uint32_t sz = 12341234;
// Instantiate object
FileAttributes fa(a, m, c, sz, attr);
uint32_t mode;
int16_t uid;
int16_t gid;
int64_t size;
time_t atime;
time_t mtime;
time_t ctime;
fa.getStat(mode, uid, gid, size, atime, mtime, ctime);
std::stringstream ss;
ss << std::hex << mode;
BOOST_TEST_MESSAGE(ss.str());
BOOST_CHECK (mode == 0x00000444);
}
//std::stringstream ss;
//ss << std::hex << mode;
//BOOST_TEST_MESSAGE(ss.str());
BOOST_CHECK (FileAttributes::convertToPosixAttributes(attr) == 0x00000444);
}
BOOST_AUTO_TEST_CASE (ConstructsFromLinuxData)
BOOST_AUTO_TEST_CASE (ReadonlyTranslatesFromLinuxToWindows)
{
// Mock up stat struct data
uint32_t md = 0x00000444;
uint16_t u = 1001;
uint16_t g = 1;
int64_t sz = 12341234;
time_t access = ATIME;
time_t modify = MTIME;
time_t create = CTIME;
// Instantiate object
FileAttributes fa(md, u, g, sz, access, modify, create);
//BOOST_TEST_MESSAGE ("Gets stat data");
{
uint32_t mode;
int16_t uid;
int16_t gid;
int64_t size;
time_t atime;
time_t mtime;
time_t ctime;
fa.getStat(mode, uid, gid, size, atime, mtime, ctime);
BOOST_CHECK (mode == 0x0000444);
BOOST_CHECK (uid == 1001);
BOOST_CHECK (gid == 1);
}
uint32_t mode = 0x00000400;
BOOST_CHECK (FileAttributes::convertToWindowsAttributes(mode) == WIN_READONLY);
}
//BOOST_TEST_MESSAGE ("Read-only permissions translate to Windows");
{
uint32_t attributes = fa.getWindowsAttributes();
uint32_t readOnlyBits = attributes & WIN_READONLY;
BOOST_CHECK (readOnlyBits != 0);
}
//BOOST_TEST_MESSAGE ("Gets FileTimePortable of accessed time");
{
FileTimePortable aFileTime = fa.getAccessedTime();
BOOST_CHECK (aFileTime.dwLowDateTime == LOW_A);
BOOST_CHECK (aFileTime.dwHighDateTime == HIGH_A);
}
//BOOST_TEST_MESSAGE ("Gets FileTimePortable of modified time");
{
FileTimePortable mFileTime = fa.getModifiedTime();
BOOST_CHECK (mFileTime.dwLowDateTime == LOW_M);
BOOST_CHECK (mFileTime.dwHighDateTime == HIGH_M);
}
BOOST_AUTO_TEST_CASE (NoPrecisionLossWithMultipleConversions)
{
// Mock up data
FileTimePortable conv;
conv.dwLowDateTime = LOW_C;
conv.dwHighDateTime = HIGH_C;
//BOOST_TEST_MESSAGE ("Gets FileTimePortable of created time");
{
FileTimePortable cFileTime = fa.getCreatedTime();
BOOST_CHECK (cFileTime.dwLowDateTime == LOW_C);
BOOST_CHECK (cFileTime.dwHighDateTime == HIGH_C);
// convert several times
for( int i = 0; i < 30; i++ ) {
time_t temp = FileAttributes::convertToPosixTime (conv);
conv = FileAttributes::convertToFileTime(temp);
}
BOOST_CHECK (conv.dwLowDateTime == LOW_C);
BOOST_CHECK (conv.dwHighDateTime == HIGH_C);
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save