summaryrefslogtreecommitdiff
path: root/csharp/test/Ice/checksum/AllTests.cs
blob: 4831da2b0cee245302fb768f435892059e01e3cb (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
// **********************************************************************
//
// 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.Collections.Generic;

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

    public static Test.ChecksumPrx
    allTests(Ice.Communicator communicator, bool collocated)
    {
        string rf = "test:default -p 12010";
        Ice.ObjectPrx baseProxy = communicator.stringToProxy(rf);
        test(baseProxy != null);

        Test.ChecksumPrx checksum = Test.ChecksumPrxHelper.checkedCast(baseProxy);
        test(checksum != null);

        //
        // Verify that no checksums are present for local types.
        //
        Console.Out.Write("testing checksums... ");
        Console.Out.Flush();
        foreach(KeyValuePair<string, string> entry in Ice.SliceChecksums.checksums)
        {
            string key = entry.Key;
            int pos = key.IndexOf("Local");
            test(pos == -1);
        }

        //
        // Get server's Slice checksums.
        //
        Dictionary<string, string> d = checksum.getSliceChecksums();

        //
        // Compare the checksums. For a type FooN whose name ends in an integer N,
        // we assume that the server's type does not change for N = 1, and does
        // change for N > 1.
        //
        char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        foreach(KeyValuePair<string, string> entry in d)
        {
            string key = entry.Key;
            int start = key.IndexOfAny(digits);
            if(start != -1)
            {
                int end = start;
                while(end < key.Length && Char.IsDigit(key[end]))
                {
                    end++;
                }
                int n = Int32.Parse(key.Substring(start, end - start));

                string value = (string)Ice.SliceChecksums.checksums[key];
                test(value != null);

                if(n <= 1)
                {
                    test(value.Equals(entry.Value));
                }
                else
                {
                    test(!value.Equals(entry.Value));
                }
            }
        }

        Console.Out.WriteLine("ok");

        return checksum;
    }
}