Test parsing of GSM 08.60 frame sync header

Tests if the frame synchronization header is correctly recognized.

The problem tested for is the following:
The sync header consists of 16 zero-bits followed by 1 one-bit. Before,
subchan_demux only tested for the 16 zero-bits. But if the previous
frame ended in one or more zero-bits these were then already counted as
belonging to the sync header, leading to a frame that was shifted by one
or more bits.
diff --git a/tests/subchan_demux/subchan_demux_test.c b/tests/subchan_demux/subchan_demux_test.c
index 75c5901..2a9a678 100644
--- a/tests/subchan_demux/subchan_demux_test.c
+++ b/tests/subchan_demux/subchan_demux_test.c
@@ -1,6 +1,7 @@
 /* Subchan Demux syncing test */
 
 /* (C) 2012 by Holger Hans Peter Freyther
+ * (C) 2012 by Tobias Engel
  *
  * All Rights Reserved
  *
@@ -25,6 +26,179 @@
 #include <stdio.h>
 #include <string.h>
 
+static uint8_t test_frames[] =
+{ 
+	/* (transmission order is from left to right) */
+	/* Frame 1 */        
+	0, 0, 0, 0, 0, 0, 0, 0, /* sync header: 16 bits zero... */
+	0, 0, 0, 0, 0, 0, 0, 0, 
+	1, 0, 1, 0, 0, 0, 1, 1, /* ... and 1 bit one (on the left) */
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 0, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 0, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1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 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 0, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 0, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, /* <== This zero-bit could be mistaken for
+				   being the start of the sync header if there
+				   is no check for the following one bit */
+	/* Frame 3 */
+	0, 0, 0, 0, 0, 0, 0, 0, 
+	0, 0, 0, 0, 0, 0, 0, 0, 
+	1, 0, 1, 0, 0, 0, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 0, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1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 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 0, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 0, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 0, 1, 1, 1, 1, 1, 1, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0, 
+	1, 1, 1, 1, 1, 1, 1, 0,
+};
+
+
+
 static int data_cb(struct subch_demux *demux, int ch, uint8_t *data, int len, void *p)
 {
 	printf("DATA_CB Channel(%d): %s\n",
@@ -34,15 +208,27 @@
 
 static void test_csd(void)
 {
+	int i;
+	uint8_t muxbyte;
 	struct subch_demux demux;
 	memset(&demux, 0, sizeof(demux));
 	subch_demux_init(&demux);
 
+	demux.chan_activ = 1;
 	demux.out_cb = data_cb;
 
 	/* Push data into the demuxer and see what happens. */
 	printf("Testing the csd sync.\n");
 
+	for(i = 0; i < sizeof(test_frames); i += 2) {
+
+		muxbyte = 0;
+		muxbyte |= test_frames[i];
+		muxbyte |= (test_frames[i+1] << 1);
+
+		subch_demux_in(&demux, &muxbyte, 1);
+	}
+
 }
 
 int main(int argc, char **argv)