summaryrefslogtreecommitdiff
path: root/csharp/test/Ice/properties/Client.cs
blob: 1ef773e55d68a3294357817a256b693d1e3845cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

using System;
using System.Reflection;

[assembly: CLSCompliant(true)]

[assembly: AssemblyTitle("IceTest")]
[assembly: AssemblyDescription("Ice test")]
[assembly: AssemblyCompany("ZeroC, Inc.")]

public class Client
{
    public static void test(bool b)
    {
        if(!b)
        {
            throw new Exception();
        }
    }

    class PropertiesClient : Ice.Application
    {
        public override int
        run(String[] args)
        {
            Ice.Properties properties = communicator().getProperties();
            test(properties.getProperty("Ice.Trace.Network").Equals("1"));
            test(properties.getProperty("Ice.Trace.Protocol").Equals("1"));
            test(properties.getProperty("Config.Path").Equals("./config/中国_client.config"));
            test(properties.getProperty("Ice.ProgramName").Equals("PropertiesClient"));
            test(appName().Equals(properties.getProperty("Ice.ProgramName")));
            return 0;
        }
    }

    public static int Main(string[] args)
    {
        int status = 0;
        try
        {
            Console.Out.Write("testing load properties from UTF-8 path... ");
            Console.Out.Flush();
            Ice.Properties properties = Ice.Util.createProperties();
            properties.load("./config/中国_client.config");
            test(properties.getProperty("Ice.Trace.Network").Equals("1"));
            test(properties.getProperty("Ice.Trace.Protocol").Equals("1"));
            test(properties.getProperty("Config.Path").Equals("./config/中国_client.config"));
            test(properties.getProperty("Ice.ProgramName").Equals("PropertiesClient"));
            Console.Out.WriteLine("ok");
            Console.Out.Write("testing load properties from UTF-8 path using Ice::Application... ");
            Console.Out.Flush();
            PropertiesClient c = new PropertiesClient();
            c.main(args, "./config/中国_client.config");
            Console.Out.WriteLine("ok");
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        //
        // Try to load multiple config files.
        //
        try
        {
            Console.Out.Write("testing using Ice.Config with multiple config files... ");
            Console.Out.Flush();
            string[] args1 = new string[]{"--Ice.Config=config/config.1, config/config.2, config/config.3"};
            Ice.Properties properties = Ice.Util.createProperties(ref args1);
            test(properties.getProperty("Config1").Equals("Config1"));
            test(properties.getProperty("Config2").Equals("Config2"));
            test(properties.getProperty("Config3").Equals("Config3"));
            Console.Out.WriteLine("ok");
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        try
        {
            Console.Out.Write("testing configuration file escapes... ");
            Console.Out.Flush();
            string[] args1 = new string[]{"--Ice.Config=config/escapes.cfg"};
            Ice.Properties properties = Ice.Util.createProperties(ref args1);

            string[] props = new string[]{"Foo\tBar", "3",
                                          "Foo\\tBar", "4",
                                          "Escape\\ Space", "2",
                                          "Prop1", "1",
                                          "Prop2", "2",
                                          "Prop3", "3",
                                          "My Prop1", "1",
                                          "My Prop2", "2",
                                          "My.Prop1", "a property",
                                          "My.Prop2", "a     property",
                                          "My.Prop3", "  a     property  ",
                                          "My.Prop4", "  a     property  ",
                                          "My.Prop5", "a \\ property",
                                          "foo=bar", "1",
                                          "foo#bar", "2",
                                          "foo bar", "3",
                                          "A", "1",
                                          "B", "2 3 4",
                                          "C", "5=#6",
                                          "AServer", "\\\\server\\dir",
                                          "BServer", "\\server\\dir",
                                          ""};

            for(int i = 0; props[i].Length > 0; i += 2)
            {
                test(properties.getProperty(props[i]).Equals(props[i + 1]));
            }
            Console.Out.WriteLine("ok");
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        return status;
    }
}