summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs
blob: 9280dfa8f2dcaf7b383cf0c8b6a1cc5f95fb62c9 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Org.Apache.Qpid.Messaging;

namespace Org.Apache.Qpid.Messaging
{
    class Program
    {
        static void Main(string[] args)
        {
            //
            // Duration test - stub until proper nunit tests are ready...

            Duration myDuration = new Duration(1234);

            Console.WriteLine("Duration should be : 1234, is : {0}",
                            myDuration.Milliseconds);

            Console.WriteLine("Duration FOREVER should be : 1.8x10^19 (realbig), is : {0}",
                            DurationConstants.FORVER.Milliseconds);

            Console.WriteLine("Duration IMMEDIATE should be : 0, is : {0}",
                            DurationConstants.IMMEDIATE.Milliseconds);

            Console.WriteLine("Duration SECOND should be : 1,000, is : {0}",
                            DurationConstants.SECOND.Milliseconds);

            Console.WriteLine("Duration MINUTE should be : 60,000, is : {0}",
                            DurationConstants.MINUTE.Milliseconds);

            Duration isInfinite = new Duration();

            Console.WriteLine("Duration() should be : realbig, is : {0}",
                            isInfinite.Milliseconds);

            Duration fiveMinutes = new Duration(DurationConstants.MINUTE.Milliseconds * 5);
            Console.WriteLine("Duration 5MINUTE should be : 300,000, is : {0}",
                            fiveMinutes.Milliseconds);

            Duration fiveSec = DurationConstants.SECOND * 5;
            Console.WriteLine("Duration 5SECOND should be : 5,000 is : {0}",
                            fiveSec.Milliseconds);
            //
            // and so on
            //

            Dictionary<string, object> dx = new Dictionary<string, object>();

            Console.WriteLine("Dictionary.GetType() {0}", dx.GetType());

            //
            // Address test
            //
            Address aEmpty = new Address();
            Address aStr   = new Address("rare");

            Dictionary<string, object> options = new Dictionary<string,object>();
            options["one"] = 1;
            options["two"] = "two";

            Address aSubj = new Address("rare2", "subj", options);

            Address aType = new Address ("check3", "subj", options, "hot");

            Console.WriteLine("aEmpty : {0}", aEmpty.ToStr());
            Console.WriteLine("aStr   : {0}", aStr.ToStr());
            Console.WriteLine("aSubj  : {0}", aSubj.ToStr());
            Console.WriteLine("aType  : {0}", aType.ToStr());

            //
            // Raw message data retrieval
            //

            Message m2 = new Message("rarey");
            UInt64 m2Size = m2.ContentSize;


            byte[] myRaw = new byte [m2Size];

            m2.GetContent(myRaw);
            Console.WriteLine("Got raw array size {0}", m2Size);
            for (UInt64 i = 0; i < m2Size; i++)
                Console.Write("{0} ", myRaw[i].ToString());
            Console.WriteLine();

            //
            // Raw message creation
            //
            byte[] rawData = new byte[10];
            for (byte i=0; i<10; i++)
                rawData[i] = i;
            Message m3 = new Message(rawData);

            byte[] rawDataReadback = new byte[m3.ContentSize];
            m3.GetContent(rawDataReadback);
            for (UInt64 i = 0; i < m3.ContentSize; i++)
                Console.Write("{0} ", rawDataReadback[i].ToString());
            Console.WriteLine();

            //
            // Raw message from array slice
            //
            byte[] rawData4 = new byte[256];
            for (int i = 0; i <= 255; i++)
                rawData4[i] = (byte)i;

            Message m4 = new Message(rawData4, 246, 10);

            byte[] rawDataReadback4 = new byte[m4.ContentSize];
            m4.GetContent(rawDataReadback4);
            for (UInt64 i = 0; i < m4.ContentSize; i++)
                Console.Write("{0} ", rawDataReadback4[i].ToString());
            Console.WriteLine();

            //
            // Set content from array slice
            //
            m4.SetContent(rawData4, 100, 5);

            byte[] rawDataReadback4a = new byte[m4.ContentSize];
            m4.GetContent(rawDataReadback4a);
            for (UInt64 i = 0; i < m4.ContentSize; i++)
                Console.Write("{0} ", rawDataReadback4a[i].ToString());
            Console.WriteLine();

            //
            // Guid factoids
            //
            Guid myGuid = new Guid("000102030405060708090a0b0c0d0e0f");
            System.Type typeP = myGuid.GetType();
            System.TypeCode typeCode = System.Type.GetTypeCode(typeP);

            Console.WriteLine("Guid Type = {0}, TypeCode = {1}",
                typeP.ToString(), typeCode.ToString());
            // typeP="System.Guid", typeCode="Object"
            byte[] guidReadback;
            guidReadback = myGuid.ToByteArray();

            Console.WriteLine("GuidReadback len = {0}", guidReadback.Length);

            //
            // Set/Get some properties of a message
            //
            Message msgGetSet = new Message("12345");

            msgGetSet.Subject = "Subject";
            msgGetSet.MessageId = "MessageId";
            msgGetSet.UserId = "UserId";
            msgGetSet.CorrelationId = "CorrelationId";
            msgGetSet.Ttl = DurationConstants.SECOND;
            msgGetSet.Priority = (byte)'z';
            msgGetSet.Durable = false;
            msgGetSet.Redelivered = true;

            Dictionary<string, object> props = new Dictionary<string,object>();
            props.Add("firstProperty", 1);
            props.Add("secondProperty", 2);
            msgGetSet.Properties = props;



            Console.WriteLine("Message Subject = {0}", msgGetSet.Subject);
            Console.WriteLine("Message ContentType = {0}", msgGetSet.ContentType);
            Console.WriteLine("Message MessageId = {0}", msgGetSet.MessageId);
            Console.WriteLine("Message UserId = {0}", msgGetSet.UserId);
            Console.WriteLine("Message CorrelationId = {0}", msgGetSet.CorrelationId);
            Console.WriteLine("Message Ttl mS = {0}", msgGetSet.Ttl.Milliseconds);
            Console.WriteLine("Message Priority = {0}", msgGetSet.Priority);
            Console.WriteLine("Message Durable = {0}", msgGetSet.Durable);
            Console.WriteLine("Message Redelivered = {0}", msgGetSet.Redelivered);

            Dictionary<string, object> gotProps = msgGetSet.Properties;
            foreach (KeyValuePair<string, object> kvp in gotProps)
            {
                Console.WriteLine("Message Property {0} = {1}", kvp.Key, kvp.Value.ToString());
            }

            Console.WriteLine("Cycle through a million address copy constructions...");
            Address a1 = new Address("abc");
            Address a2 = new Address("def");
            Address a3 = new Address(a2);
            for (int i = 0; i < 1000000; i++)
            {
                a1 = a2;
                a2 = a3;
                a3 = new Address(a1);
            }
            Console.WriteLine("                                                  ...done.");

            Console.WriteLine("Use each object's copy constructor");

            Address Address1 = new Address("abc");
            Address Address2 = new Address(Address1);

            Connection Connection1 = new Connection("abc");
            Connection Connection2 = new Connection(Connection1);

            Message Message1 = new Message("abc");
            Message Message2 = new Message(Message1);


        }
    }
}