xref: /trunk/main/tools/workben/fstest.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_tools.hxx"
30 
31 #define _FSTEST_CXX "$Revision: 1.5 $"
32 #include <tools/solar.h>
33 
34 #include <stdio.h>
35 #include <tools/stream.hxx>
36 #include <tools/fsys.hxx>
37 #include <tools/date.hxx>
38 #include <tools/time.hxx>
39 
40 void CheckTimes(DirEntry aDE);
41 
42 /*
43  * main.
44  */
45 int main (int argc, char **argv)
46 {
47     DirEntry aDir;
48     if (aDir.Exists())
49     {
50         aDir.ToAbs();
51         String sTmp(aDir.GetFull(FSYS_STYLE_HOST));
52         printf("Directory = %s\n", sTmp.GetStr());
53         CheckTimes(aDir);
54         DirEntry aFile =
55             aDir + DirEntry("testfile.txt", FSYS_STYLE_HOST);
56         SvFileStream aStream;
57         aStream.Open(aFile.GetFull(FSYS_STYLE_HOST), STREAM_WRITE);
58         aStream << "Test";
59         aStream.Close();
60         ULONG i, nWaitFor = 2000 + Time::GetSystemTicks();
61         for (i=Time::GetSystemTicks();
62                  i < nWaitFor;
63                  i = Time::GetSystemTicks())
64             ;
65         CheckTimes(aDir);
66         nWaitFor = 2000 + Time::GetSystemTicks();
67         for (i=Time::GetSystemTicks();
68                  i < nWaitFor;
69                  i = Time::GetSystemTicks())
70             ;
71         aFile.Kill();
72     }
73     else
74         puts("MakeDir failed!");
75     return 0;
76 }
77 
78 void CheckTimes(DirEntry aDE)
79 {
80     FileStat aDirStat(aDE);
81     aDirStat.Update(aDE);
82     Date aDateCreated(aDirStat.DateCreated());
83     Date aDateModified(aDirStat.DateModified());
84     Time aTimeCreated(aDirStat.TimeCreated());
85     Time aTimeModified(aDirStat.TimeModified());
86     printf(
87         "DirDateCreated = %i, DirTimeCreated = %i\n",
88         aDateCreated.GetDate(), aTimeCreated.GetTime());
89     printf(
90         "DirDateModified = %i, DirTimeModified = %i\n",
91         aDateModified.GetDate(), aTimeModified.GetTime());
92     return;
93 }
94 
95