package edu.brown.cs.systems.xtrace.logging;

import org.aspectj.lang.JoinPoint.StaticPart;
import org.junit.Test;

import com.google.protobuf.ByteString;

import edu.brown.cs.systems.baggage.Baggage;
import edu.brown.cs.systems.baggage.DetachedBaggage;
import junit.framework.TestCase;

public class TestBaggageWrappers extends TestCase {
    
    private static class TestLogger implements XTraceLogger {
        
        int logCount, tagCount, logJoinCount, tagJoinCount; 

        public boolean valid() {
            return true;
        }

        public boolean valid(XTraceLoggingLevel level) {
            return true;
        }

        public void log(String message, Object... labels) {
            logCount++;
        }

        public void tag(String message, String... tags) {
            tagCount++;
        }

        public void log(StaticPart joinPoint, String message, Object... labels) {
            logJoinCount++;
        }

        public void tag(StaticPart joinPoint, String message, String... tags) {
            tagJoinCount++;
        }
        
        public void check(int log, int tag, int logJoin, int tagJoin) {
            TestCase.assertEquals(log, logCount);
            TestCase.assertEquals(tag, tagCount);
            TestCase.assertEquals(logJoin, logJoinCount);
            TestCase.assertEquals(tagJoin, tagJoinCount);
        }
    }

    @Test
    public void testBaggageWrappers() {
        TestLogger logger = new TestLogger();
        BaggageWrappers.xtrace = logger;
        
        logger.check(0,0,0,0);
        logger.log("hello");
        logger.check(0,0,1,0);
        
        Baggage.start();
        logger.check(0,0,3,0);
        
        Baggage.start((byte[]) null);
        logger.check(0,0,5,0);
        
        Baggage.start((ByteString) null);
        logger.check(0,0,7,0);
        
        Baggage.start((DetachedBaggage) null);
        logger.check(0,0,9,0);
        
        Baggage.start("");
        logger.check(0,0,11,0);
        
        Baggage.stop();
        logger.check(0,0,13,0);
        
        Baggage.fork();
        logger.check(0,0,15,0);
        
        Baggage.join((byte[]) null);
        logger.check(0,0,17,0);
        
        Baggage.join((ByteString) null);
        logger.check(0,0,19,0);
        
        Baggage.join((DetachedBaggage) null);
        logger.check(0,0,21,0);
        
        Baggage.join("");
        logger.check(0,0,23,0);
    }
    
}

@@ -1670,17 +1670,17 @@
 eck(0,0,
-3
+2
 ,0);%0A   
@@ -1748,17 +1748,17 @@
 eck(0,0,
-5
+3
 ,0);%0A   
@@ -1830,17 +1830,17 @@
 eck(0,0,
-7
+4
 ,0);%0A   
@@ -1917,17 +1917,17 @@
 eck(0,0,
-9
+5
 ,0);%0A   
@@ -1988,10 +1988,9 @@
 0,0,
-11
+6
 ,0);
@@ -2052,10 +2052,9 @@
 0,0,
-13
+7
 ,0);
@@ -2116,10 +2116,9 @@
 0,0,
-15
+8
 ,0);
@@ -2193,10 +2193,9 @@
 0,0,
-17
+9
 ,0);
@@ -2271,17 +2271,17 @@
 ck(0,0,1
-9
+0
 ,0);%0A   
@@ -2357,17 +2357,17 @@
 eck(0,0,
-2
+1
 1,0);%0A  
@@ -2428,10 +2428,10 @@
 0,0,
+1
 2
-3
 ,0);

Update test to reflect previous commit