Torque3D Documentation / _generateds / platformFileIOTest.cpp

platformFileIOTest.cpp

Engine/source/platform/test/platformFileIOTest.cpp

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifdef TORQUE_TESTS_ENABLED
 25#include "testing/unitTesting.h"
 26#include "platform/platform.h"
 27#include "core/fileio.h"
 28#include "core/util/tVector.h"
 29#include "console/console.h"
 30
 31TEST(Platform, ExcludedDirectories)
 32{
 33   // Just dump everything under the current directory. We should
 34   // find at least one file.
 35
 36   // Exclude .svn and CVS
 37   Platform::clearExcludedDirectories();
 38   Platform::addExcludedDirectory(".svn");
 39   Platform::addExcludedDirectory("CVS");
 40
 41   EXPECT_TRUE(Platform::isExcludedDirectory(".svn"))
 42      << "On list, should be excluded.";
 43   EXPECT_TRUE(Platform::isExcludedDirectory("CVS"))
 44      << "On list, should be excluded.";
 45   EXPECT_FALSE(Platform::isExcludedDirectory("foo"))
 46      << "Doesn't match list, shouldn't be excluded.";
 47   EXPECT_FALSE(Platform::isExcludedDirectory(".svnCVS"))
 48      << "Looks like a duck, but it shouldn't be excluded cuz it's distinct from all entries on the exclusion list.";
 49
 50   // Ok, now our exclusion list is setup, so let's dump some paths.
 51   Vector<Platform::FileInfo> pathInfo;
 52   Platform::dumpPath(Platform::getCurrentDirectory(), pathInfo, 2);
 53   EXPECT_GT(pathInfo.size(), 0)
 54      << "Should find at least SOMETHING in the current directory!";
 55
 56   // This'll nuke info if we run it in a live situation... so don't run unit
 57   // tests in a live situation. ;)
 58   Platform::clearExcludedDirectories();
 59};
 60
 61TEST(File, TouchAndTime)
 62{
 63   FileTime create[2], modify[2];
 64
 65   // Create a file and sleep for a second.
 66   File f;
 67   f.open("testTouch.file", File::WriteAppend);
 68   f.close();
 69
 70   // Touch a file and note its last-modified.
 71   dFileTouch("testTouch.file");
 72   EXPECT_TRUE(Platform::isFile("testTouch.file"))
 73      << "We just touched this file - it should exist.";
 74   EXPECT_TRUE(Platform::getFileTimes("testTouch.file", &create[0], &modify[0]))
 75      << "Failed to get filetimes for a file we just created.";
 76
 77   // Sleep for a tick
 78   Platform::sleep(10);
 79
 80   // Touch it again, and compare the last-modifieds.
 81   EXPECT_TRUE(Platform::isFile("testTouch.file"))
 82      << "We just touched this file - it should exist.";
 83   dFileTouch("testTouch.file");
 84   EXPECT_TRUE(Platform::isFile("testTouch.file"))
 85      << "We just touched this file - it should exist.";
 86   EXPECT_TRUE(Platform::getFileTimes("testTouch.file", &create[1], &modify[1]))
 87      << "Failed to get filetimes for a file we just created.";
 88
 89   // Now compare the times...
 90   EXPECT_LT(Platform::compareFileTimes(modify[0], modify[1]), 0)
 91      << "Timestamps are wrong - modify[0] should be before modify[1]!";
 92   EXPECT_EQ(Platform::compareFileTimes(create[0], create[1]), 0)
 93      << "Create timestamps should match - we didn't delete the file during this test.";
 94
 95   // Clean up..
 96   dFileDelete("testTouch.file");
 97   EXPECT_FALSE(Platform::isFile("testTouch.file"))
 98      << "Somehow failed to delete our test file.";
 99};
100
101// Mac/Linux have no implementations for these functions, so we 'def it out for now.
102#ifdef WIN32
103TEST(Platform, Volumes)
104{
105   Vector<const char*> names;
106   Platform::getVolumeNamesList(names);
107
108   EXPECT_GT(names.size(), 0)
109      << "We should have at least one volume...";
110
111   Vector<Platform::VolumeInformation> info;
112   Platform::getVolumeInformationList(info);
113
114   EXPECT_EQ(names.size(), info.size())
115      << "Got inconsistent number of volumes back from info vs. name list functions!";
116};
117#endif
118
119#endif
120