// Compiler options: -unsafe -r:gtest-166-lib.dll

// Fixed buffers tests

using System;

public unsafe struct TestNew {
	private fixed char test_1 [128];
	public fixed bool test2 [4];
	
	public fixed int T [2];
	public fixed bool test20 [4], test21 [40];
	
	private int foo, foo2;
	public void SetTest () {
		fixed (char* c = test_1) {
			*c = 'g';
		}
	}
}

public class C {
	unsafe static int Test () {
		TestNew tt = new TestNew ();
		tt.SetTest ();
		tt.test2 [2] = false;
		tt.T [1] = 5544;
		if (tt.T [1] != 5544)
			return 2;
	
		ExternalStruct es = new ExternalStruct ();
		es.double_buffer [1] = 999999.8888;
		es.double_buffer [0] = es.double_buffer [1];

		// Attributes test
		if (Attribute.GetCustomAttribute (typeof (TestNew).GetField ("test2"), typeof (System.Runtime.CompilerServices.FixedBufferAttribute)) == null)
			return 3;

		
		if (typeof (TestNew).GetNestedTypes ().Length != 5)
			return 5;

		foreach (Type t in typeof (TestNew).GetNestedTypes ()) {
			if (Attribute.GetCustomAttribute (t, typeof (System.Runtime.CompilerServices.CompilerGeneratedAttribute)) == null)
				return 4;
		}

		Console.WriteLine ("OK");
		return 0;
	}
    
	public static int Main () {
		return Test ();
	}
}
