2010-05-19 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / gtest-initialize-02.cs
bloba647a4bb344bfb10d186f739fda18bd4c7bd2da7
2 // Uber-test for object and collection initialization
3 using System;
4 using System.Collections.Generic;
6 public class Test
8 private class Point
10 public int X;
11 public int Y;
13 private class Line
15 public Point P1 = new Point ();
16 public Point P2 = new Point ();
18 private class Rectangle
20 public Line Top = new Line ();
21 public Line Right = new Line ();
22 public Line Left = new Line ();
23 public Line Bottom = new Line ();
25 private class Library
27 public string Name;
28 public string PhoneNumber;
29 public List<string> Books;
30 public Library ()
32 Books = new List<string> { "Tale of Two Cities", "Catcher in the Rye", "Great Gatsby" };
35 private class Thing
37 public int Number;
38 public string Name;
40 private class Box
42 public Thing Thing1;
43 public Thing Thing2;
45 static int Main ()
47 Thing thing1 = new Thing() { Number = 1, Name = "Bob" };
49 Line line = new Line { P1 = { X = 1, Y = 5 }, P2 = { X = 3, Y = 6 } };
50 if (line.P1.X != 1 || line.P1.Y != 5 || line.P2.X != 3 || line.P2.Y != 6)
51 return 1;
53 Rectangle rectangle = new Rectangle () {
54 Top = {
55 P1 = { X = 0, Y = 5 },
56 P2 = { X = 5, Y = 5 } },
57 Bottom = {
58 P1 = { X = 0, Y = 0, },
59 P2 = { X = 5, Y = 0, }, },
60 Right = {
61 P1 = { X = 5, Y = 5 },
62 P2 = { X = 5, Y = 0 } },
63 Left = {
64 P1 = { X = 0, Y = 0, },
65 P2 = { X = 0, Y = 5 } } };
66 if (rectangle.Top.P1.X != 0 || rectangle.Bottom.P2.X != 5 || rectangle.Right.P2.Y != 0 || rectangle.Left.P1.Y != 0)
67 return 2;
69 List<string> list = new List<string> (3) { "Foo", "Bar", "Baz" };
70 if (list[0] != "Foo" || list[1] != "Bar" || list[2] != "Baz")
71 return 3;
73 Library library = new Library {
74 Name = "New York Public Library",
75 Books = { "Grapes of Wrath", "Dracula", },
76 PhoneNumber = "212-621-0626" };
77 if (library.Name != "New York Public Library" || library.PhoneNumber != "212-621-0626" ||
78 library.Books[0] != "Tale of Two Cities" ||
79 library.Books[1] != "Catcher in the Rye" ||
80 library.Books[2] != "Great Gatsby" ||
81 library.Books[3] != "Grapes of Wrath" ||
82 library.Books[4] != "Dracula")
83 return 4;
85 Box box = new Box {
86 Thing1 = new Thing { Number = 1, Name = "Wilber" },
87 Thing2 = new Thing() { Number = 2, Name = "Chris" } };
88 if (box.Thing1.Number != 1 || box.Thing1.Name != "Wilber" || box.Thing2.Number != 2 || box.Thing2.Name != "Chris")
89 return 5;
91 Library library2 = new Library { Books = new List<string> { "The Hound of Baskerville", "Flatland", "The Origin of Species" } };
92 if (library2.Books[0] != "The Hound of Baskerville" ||
93 library2.Books[1] != "Flatland" ||
94 library2.Books[2] != "The Origin of Species")
95 return 6;
97 return 0;