tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 1 | // Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | // Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | // Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | // This library was generated by the LoxiGen Compiler. |
| 5 | // See the file LICENSE.txt which should have been included in the source distribution |
| 6 | |
| 7 | // Automatically generated by LOXI from template unit_test.java |
| 8 | // Do not modify |
| 9 | |
| 10 | package org.projectfloodlight.openflow.protocol.ver13; |
| 11 | |
| 12 | import org.projectfloodlight.openflow.protocol.*; |
| 13 | import org.projectfloodlight.openflow.protocol.action.*; |
| 14 | import org.projectfloodlight.openflow.protocol.actionid.*; |
| 15 | import org.projectfloodlight.openflow.protocol.bsntlv.*; |
| 16 | import org.projectfloodlight.openflow.protocol.errormsg.*; |
| 17 | import org.projectfloodlight.openflow.protocol.meterband.*; |
| 18 | import org.projectfloodlight.openflow.protocol.instruction.*; |
| 19 | import org.projectfloodlight.openflow.protocol.instructionid.*; |
| 20 | import org.projectfloodlight.openflow.protocol.match.*; |
| 21 | import org.projectfloodlight.openflow.protocol.oxm.*; |
| 22 | import org.projectfloodlight.openflow.protocol.queueprop.*; |
| 23 | import org.projectfloodlight.openflow.types.*; |
| 24 | import org.projectfloodlight.openflow.util.*; |
| 25 | import org.projectfloodlight.openflow.exceptions.*; |
| 26 | import static org.junit.Assert.*; |
| 27 | import org.junit.Test; |
| 28 | import org.junit.Before; |
| 29 | import org.jboss.netty.buffer.ChannelBuffer; |
| 30 | import org.jboss.netty.buffer.ChannelBuffers; |
| 31 | import org.hamcrest.CoreMatchers; |
| 32 | |
| 33 | |
| 34 | |
| 35 | public class OFBadMatchErrorMsgVer13Test { |
| 36 | OFErrorMsgs factory; |
| 37 | |
| 38 | final static byte[] BAD_MATCH_ERROR_MSG_SERIALIZED = |
| 39 | new byte[] { 0x4, 0x1, 0x0, 0xf, 0x12, 0x34, 0x56, 0x78, 0x0, 0x4, 0x0, 0x8, 0x61, 0x62, 0x63 }; |
| 40 | |
| 41 | @Before |
| 42 | public void setup() { |
| 43 | factory = OFErrorMsgsVer13.INSTANCE; |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testWrite() { |
| 48 | OFBadMatchErrorMsg.Builder builder = factory.buildBadMatchErrorMsg(); |
| 49 | builder.setXid(0x12345678) |
| 50 | .setCode(OFBadMatchCode.BAD_MASK) |
| 51 | .setData(OFErrorCauseData.of(new byte[] { 0x61, 0x62, 0x63 }, OFVersion.OF_13));; |
| 52 | OFBadMatchErrorMsg badMatchErrorMsg = builder.build(); |
| 53 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 54 | badMatchErrorMsg.writeTo(bb); |
| 55 | byte[] written = new byte[bb.readableBytes()]; |
| 56 | bb.readBytes(written); |
| 57 | |
| 58 | assertThat(written, CoreMatchers.equalTo(BAD_MATCH_ERROR_MSG_SERIALIZED)); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void testRead() throws Exception { |
| 63 | OFBadMatchErrorMsg.Builder builder = factory.buildBadMatchErrorMsg(); |
| 64 | builder.setXid(0x12345678) |
| 65 | .setCode(OFBadMatchCode.BAD_MASK) |
| 66 | .setData(OFErrorCauseData.of(new byte[] { 0x61, 0x62, 0x63 }, OFVersion.OF_13));; |
| 67 | OFBadMatchErrorMsg badMatchErrorMsgBuilt = builder.build(); |
| 68 | |
| 69 | ChannelBuffer input = ChannelBuffers.copiedBuffer(BAD_MATCH_ERROR_MSG_SERIALIZED); |
| 70 | |
| 71 | // FIXME should invoke the overall reader once implemented |
| 72 | OFBadMatchErrorMsg badMatchErrorMsgRead = OFBadMatchErrorMsgVer13.READER.readFrom(input); |
| 73 | assertEquals(BAD_MATCH_ERROR_MSG_SERIALIZED.length, input.readerIndex()); |
| 74 | |
| 75 | assertEquals(badMatchErrorMsgBuilt, badMatchErrorMsgRead); |
| 76 | } |
| 77 | |
| 78 | @Test |
| 79 | public void testReadWrite() throws Exception { |
| 80 | ChannelBuffer input = ChannelBuffers.copiedBuffer(BAD_MATCH_ERROR_MSG_SERIALIZED); |
| 81 | |
| 82 | // FIXME should invoke the overall reader once implemented |
| 83 | OFBadMatchErrorMsg badMatchErrorMsg = OFBadMatchErrorMsgVer13.READER.readFrom(input); |
| 84 | assertEquals(BAD_MATCH_ERROR_MSG_SERIALIZED.length, input.readerIndex()); |
| 85 | |
| 86 | // write message again |
| 87 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 88 | badMatchErrorMsg.writeTo(bb); |
| 89 | byte[] written = new byte[bb.readableBytes()]; |
| 90 | bb.readBytes(written); |
| 91 | |
| 92 | assertThat(written, CoreMatchers.equalTo(BAD_MATCH_ERROR_MSG_SERIALIZED)); |
| 93 | } |
| 94 | |
| 95 | } |