xref: /AOO41X/main/sal/workben/t_osl_getVolInfo.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_sal.hxx"
30 
31 #include <cppunit/simpleheader.hxx>
32 #include <osl/file.h>
33 #include <rtl/ustring.hxx>
34 
35 #ifdef WNT
36 #   define  TEST_PATH_1 "c:\\"
37 #   define  TEST_PATH_2 "c:\\mnt\\MSDN"
38 #   define  TEST_PATH_3 "c:\\Program Files"
39 #   define  TEST_PATH_4 "\\\\Tra-1\\mnt\\c"
40 #   define  TEST_PATH_5 "\\\\Tra-1\\mnt"
41 #   define  TEST_PATH_6 "\\\\Tra-1\\mnt\\c\\"
42 #else // UNX
43 #   define  TEST_PATH_1 "/net/athene/export/home/tra"
44 #   define  TEST_PATH_2 "/net/athene/export/home/tra/"
45 #   define  TEST_PATH_3 "/"
46 #   define  TEST_PATH_4 "."
47 #   define  TEST_PATH_5 "/net/athene/export/home/tra/projects"
48 #   define  TEST_PATH_6 "/blah"
49 #endif
50 
51 //------------------------------
52 //
53 //------------------------------
54 
55 void test_getVolumeInformation(const rtl::OUString& path_url)
56     {
57         oslVolumeInfo vi;
58         memset((void*)&vi, 0, sizeof(vi));
59         vi.uStructSize   = sizeof(vi);
60         vi.pDeviceHandle = NULL;
61 
62         oslFileError err = osl_getVolumeInformation(
63             path_url.pData,
64             &vi,
65             osl_VolumeInfo_Mask_Attributes |
66             osl_VolumeInfo_Mask_TotalSpace |
67             osl_VolumeInfo_Mask_UsedSpace |
68             osl_VolumeInfo_Mask_FreeSpace |
69             osl_VolumeInfo_Mask_MaxNameLength |
70             osl_VolumeInfo_Mask_MaxPathLength |
71             osl_VolumeInfo_Mask_FileSystemName |
72             osl_VolumeInfo_Mask_DeviceHandle);
73 
74         CPPUNIT_ASSERT_MESSAGE
75         (
76             "osl_getVolumeInformation failed",
77             err == osl_File_E_None
78         );
79     }
80 
81 //------------------------------
82 //
83 //------------------------------
84 
85 class TestClass_osl_getVolumeInformation : public CppUnit::TestFixture
86 {
87 public:
88 
89     /*-------------------------------------
90         Start a process and join with this
91         process specify a timeout so that
92         osl_joinProcessWithTimeout returns
93         osl_Process_E_TimedOut
94      -------------------------------------*/
95 
96     void test_osl_getVolumeInformation()
97     {
98         rtl::OUString path = rtl::OUString::createFromAscii(TEST_PATH_1);
99         rtl::OUString path_url;
100         osl_getFileURLFromSystemPath(path.pData, &path_url.pData);
101         test_getVolumeInformation(path_url);
102 
103         path = rtl::OUString::createFromAscii(TEST_PATH_2);
104         osl_getFileURLFromSystemPath(path.pData, &path_url.pData);
105         test_getVolumeInformation(path_url);
106 
107         path = rtl::OUString::createFromAscii(TEST_PATH_3);
108         osl_getFileURLFromSystemPath(path.pData, &path_url.pData);
109         test_getVolumeInformation(path_url);
110 
111         path = rtl::OUString::createFromAscii(TEST_PATH_4);
112         osl_getFileURLFromSystemPath(path.pData, &path_url.pData);
113         test_getVolumeInformation(path_url);
114 
115         path = rtl::OUString::createFromAscii(TEST_PATH_5);
116         osl_getFileURLFromSystemPath(path.pData, &path_url.pData);
117         test_getVolumeInformation(path_url);
118 
119         path = rtl::OUString::createFromAscii(TEST_PATH_6);
120         osl_getFileURLFromSystemPath(path.pData, &path_url.pData);
121         test_getVolumeInformation(path_url);
122     }
123 
124     CPPUNIT_TEST_SUITE( TestClass_osl_getVolumeInformation );
125     CPPUNIT_TEST( test_osl_getVolumeInformation );
126     CPPUNIT_TEST_SUITE_END( );
127 };
128 
129 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestClass_osl_getVolumeInformation, "Test osl_getVolumeInformation");
130 
131 NOADDITIONAL;
132 
133