#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include "LockFreeQueue.h"

/*
14    
15    [TestMethod]
16    [HostType("Chess")]
17    [TestProperty("ChessMonitorVolatiles","True")]
18    public void TestLockFreeQueueWithError1(){
19      QueueTest qt = new QueueTest();
20      LockFreeQueue lfq = 
21          new LockFreeQueueWithError1();
22      EnqContainer firstParams, secondParams;
23      firstParams.q = secondParams.q = lfq;
24      firstParams.first = "a";
25      firstParams.second = "b";
26      secondParams.first = "c";
27      secondParams.second = "d";
28      Thread t2 = new Thread(
29                    new ParameterizedThreadStart(
30                                qt.EnqTwoStrings));
31      t2.start(secondParams);
32      QueueTwoItems(firstParams);
33      t2.join();
34      
35        // Test - Verify that the head is 
36        //   connected to the tail and that
37        //   the tail is exactly 4 nodes 
38        //   away from the head.
39      Node current = lfq.head;
40      for (int i = 0; i < 4; i++)
41        current = current.next;
42      Assert.IsTrue (current == lfq.tail);
43    }
44  }
*/
void TestLockFreeQueueWithError1 () {
	int i;
	pthread_t t1, t2;
	LockFreeQueue *lfq = NewLockFreeQueue();
	EnqContainer firstParams, secondParams;	
	
	firstParams.queue = secondParams.queue = lfq;
	firstParams.first = "a";
	firstParams.second = "b";
	secondParams.first = "c";
	secondParams.second = "d";

	pthread_create(&t1, NULL, EnqTwoStrings_WithError1, &firstParams);
	pthread_create(&t2, NULL, EnqTwoStrings_WithError1, &secondParams);
	pthread_join(t1, NULL);
	pthread_join(t2, NULL);	

	Node *current = lfq->head;
	for (i = 0 ; i < 4 ; i++) {
		current = current->next;
		assert(current != NULL);
		printf("%d: %s\n", i, (char*)current->val);
	}
}	


int main (void) {
	TestLockFreeQueueWithError1 ();
	return 0;
}


