| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- /*******************************************************************************
- * Copyright (c) 2009, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
- #include <CppUTest/TestHarness.h>
- #include <stdint.h>
- #include <string.h>
- extern "C" {
- #include "cipepath.h"
- #include "cipelectronickey.h"
- }
- TEST_GROUP(CipElectronicKey) {
- ElectronicKeyFormat4 *key = NULL;
- void setup() {
- key = ElectronicKeyFormat4New();
- }
- void teardown() {
- ElectronicKeyFormat4Delete(&key);
- }
- };
- TEST(CipElectronicKey, CreateElectronicKey) {
- char dummyArea[kElectronicKeyFormat4Size] = {0};
- MEMCMP_EQUAL(dummyArea, key, kElectronicKeyFormat4Size);
- };
- TEST(CipElectronicKey, DeleteElectronicKey) {
- ElectronicKeyFormat4Delete(&key);
- POINTERS_EQUAL(NULL, key);
- }
- TEST(CipElectronicKey, SetVendorID) {
- char demoArea[kElectronicKeyFormat4Size] = {0};
- CipUint *vendor_id = (CipUint *)demoArea;
- *vendor_id = 1;
- ElectronicKeyFormat4SetVendorId(1, key);
- MEMCMP_EQUAL(demoArea, key, kElectronicKeyFormat4Size);
- }
- TEST(CipElectronicKey, GetVendorID) {
- CipUint expected_vendor_id = 1;
- CipUint *vendor_id_data = (CipUint *)key;
- *vendor_id_data = expected_vendor_id;
- CipUint vendor_id = ElectronicKeyFormat4GetVendorId(key);
- CHECK_EQUAL(expected_vendor_id, vendor_id);
- }
- TEST(CipElectronicKey, SetDeviceType) {
- char demoArea[kElectronicKeyFormat4Size] = {0};
- CipUint *device_type = (CipUint *)demoArea + 1;
- *device_type = 1;
- ElectronicKeyFormat4SetDeviceType(1, key);
- MEMCMP_EQUAL(demoArea, key, kElectronicKeyFormat4Size);
- }
- TEST(CipElectronicKey, GetDeviceType) {
- CipUint expected_device_type = 1;
- CipUint *device_type_data = (CipUint *)key + 1;
- *device_type_data = expected_device_type;
- CipUint device_type = ElectronicKeyFormat4GetDeviceType(key);
- CHECK_EQUAL(expected_device_type, device_type);
- }
- TEST(CipElectronicKey, SetProductCode) {
- char demoArea[kElectronicKeyFormat4Size] = {0};
- CipUint *product_code = (CipUint *)demoArea + 2;
- *product_code = 1;
- ElectronicKeyFormat4SetProductCode(1, key);
- MEMCMP_EQUAL(demoArea, key, kElectronicKeyFormat4Size);
- }
- TEST(CipElectronicKey, GetProductCode) {
- CipUint expected_product_code = 1;
- CipUint *product_code_data = (CipUint *)key + 2;
- *product_code_data = expected_product_code;
- CipUint product_code = ElectronicKeyFormat4GetProductCode(key);
- CHECK_EQUAL(expected_product_code, product_code);
- }
- TEST(CipElectronicKey, SetMajorRevisionCompatibility) {
- char demoArea[kElectronicKeyFormat4Size] = {0};
- CipByte *major_revision_compatiblitiy = (CipByte *)demoArea + 6;
- *major_revision_compatiblitiy = 0x81;
- ElectronicKeyFormat4SetMajorRevisionCompatibility(0x81, key);
- MEMCMP_EQUAL(demoArea, key, kElectronicKeyFormat4Size);
- }
- TEST(CipElectronicKey, GetMajorRevision) {
- CipUint expected_major_revision = 0x1;
- CipUint set_major_revision = 0x1;
- CipByte *expected_major_data = (CipByte *)key + 6;
- *expected_major_data = set_major_revision;
- CipUint product_code = ElectronicKeyFormat4GetMajorRevision(key);
- CHECK_EQUAL(expected_major_revision, product_code);
- }
- TEST(CipElectronicKey, GetMajorRevisionCompatibility) {
- CipUint expected_major_revision = 0x81;
- CipByte *expected_major_data = (CipByte *)key + 6;
- *expected_major_data = expected_major_revision;
- bool compatibility = ElectronicKeyFormat4GetMajorRevisionCompatibility(key);
- CHECK_TEXT(compatibility, "Compatibility flag not working");
- }
- TEST(CipElectronicKey, SetMinorRevision) {
- char demoArea[kElectronicKeyFormat4Size] = {0};
- CipByte *minor_revision_compatiblitiy = (CipByte *)demoArea + 7;
- *minor_revision_compatiblitiy = 0x81;
- ElectronicKeyFormat4SetMinorRevision(0x81, key);
- MEMCMP_EQUAL(demoArea, key, kElectronicKeyFormat4Size);
- }
- TEST(CipElectronicKey, GetMinorRevision) {
- CipUint expected_minor_revision = 0x1;
- CipByte *expected_minor_data = (CipByte *)key + 7;
- *expected_minor_data = expected_minor_revision;
- CipUint product_code = ElectronicKeyFormat4GetMinorRevision(key);
- CHECK_EQUAL(expected_minor_revision, product_code);
- }
- TEST(CipElectronicKey, ParseElectronicKeyTest) {
- /* Size of an electronic key is 1 + 1 + 8 (Segment, Key format, Key) */
- const unsigned char message[] =
- {0x34, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x04, 0x05};
- GetPathLogicalSegmentElectronicKeyFormat4(message, key);
- CHECK_EQUAL( 256, ElectronicKeyFormat4GetVendorId(key) );
- CHECK_EQUAL( 512, ElectronicKeyFormat4GetDeviceType(key) );
- MEMCMP_EQUAL(message + 2, key, 8);
- }
|