update dev300-m58
[ooovba.git] / cppu / test / env_tester / env.tester.cxx
blob97d21830ff1a9e77d3d364503fe25e495eb8f8a2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: env.tester.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <iostream>
33 #include "sal/main.h"
34 #include "rtl/ustring.hxx"
35 #include "rtl/string.hxx"
36 #include "rtl/alloc.h"
37 #include "uno/environment.hxx"
38 #include "uno/lbnames.h"
40 using namespace com::sun::star;
43 static rtl::OUString s_replaceCPP(rtl::OUString const & str)
45 rtl::OUString cpp(RTL_CONSTASCII_USTRINGPARAM("CPP"));
47 rtl::OUString result;
49 sal_Int32 index_old = 0;
50 sal_Int32 index = str.indexOf(cpp, index_old);
51 while (index != -1)
53 result += str.copy(index_old, index - index_old);
54 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV)));
56 index_old = index + 3;
57 index = str.indexOf(cpp, index_old);
59 result += str.copy(index_old);
61 return result;
65 rtl::OUString register_test(rtl::OUString const & envDcp);
66 rtl::OUString purpenv_test(rtl::OUString const & envDcp);
70 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
72 int ret = 0;
73 rtl::OUString message;
75 if (argc == 2)
77 message = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
79 rtl::OUString envDcp(argv[1], rtl_str_getLength(argv[1]), RTL_TEXTENCODING_ASCII_US);
80 envDcp = s_replaceCPP(envDcp);
83 message += register_test(envDcp);
84 message += purpenv_test(envDcp);
86 if (message.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILURE"))) == -1)
88 message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n"));
89 ret = 0;
91 else
93 message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n"));
94 ret = -1;
97 else
98 message = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("<env. descriptor>"));
100 std::cerr
101 << argv[0]
102 << " "
103 << rtl::OUStringToOString(message, RTL_TEXTENCODING_ASCII_US).getStr()
104 << std::endl;
106 return ret;