BaseAdminTest.cxx
上传用户:xfwatch
上传日期:2020-12-14
资源大小:872k
文件大小:3k
- /*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat, Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
- #include "TestAssert.h"
- #include "ace/OS_NS_stdlib.h"
- #include "ace/OS_NS_stdio.h"
- #include "ace/OS_NS_string.h"
- #include "xatmi.h"
- #include "userlogc.h"
- #include "BaseAdminTest.h"
- void BaseAdminTest::setUp() {
- BaseServerTest::setUp();
- }
- void BaseAdminTest::tearDown() {
- BaseServerTest::tearDown();
- }
- int BaseAdminTest::callADMIN(char* command, char expect, int r, char** n) {
- userlogc("Command was %s", command);
- long sendlen = strlen(command) + 1;
- char* sendbuf = tpalloc((char*) "X_OCTET", NULL, sendlen);
- strcpy(sendbuf, command);
- char* recvbuf = tpalloc((char*) "X_OCTET", NULL, 1);
- long recvlen = 1;
- int cd = ::tpcall((char*) "default_ADMIN_1", (char *) sendbuf, sendlen, (char**)&recvbuf, &recvlen, TPNOTRAN);
- BT_ASSERT(r != -1);
- BT_ASSERT(recvbuf[0] == expect);
- BT_ASSERT(r == tperrno);
- if(ACE_OS::strncmp(command, "counter", 7) == 0 ||
- ACE_OS::strncmp(command, "error_counter", 13) == 0 ||
- ACE_OS::strncmp(command, "version", 7) == 0) {
- *n = (char*) malloc(recvlen);
- memset(*n, 0, recvlen);
- memcpy(*n, &recvbuf[1], recvlen -1);
- } else if(ACE_OS::strncmp(command, "status", 6) == 0) {
- userlogc((char*) "len is %d, service status: %s", recvlen, &recvbuf[1]);
- }
- tpfree(sendbuf);
- tpfree(recvbuf);
- return cd;
- }
- int BaseAdminTest::callBAR(int r, char* buf) {
- if(buf == NULL) {
- buf = (char*) "test";
- }
- long sendlen = strlen(buf) + 1;
- char* sendbuf = tpalloc((char*) "X_OCTET", NULL, sendlen);
- strcpy(sendbuf, buf);
- char* recvbuf = tpalloc((char*) "X_OCTET", NULL, 1);
- long recvlen = 1;
- int cd = ::tpcall((char*) "BAR", (char *) sendbuf, sendlen, (char**)&recvbuf, &recvlen, 0);
- if (r == 0) {
- char* tperrnoS = (char*) malloc(110);
- sprintf(tperrnoS, "%d", tperrno);
- BT_ASSERT_MESSAGE(tperrnoS, cd != -1);
- free(tperrnoS);
- } else {
- char* tperrnoS = (char*) malloc(110);
- sprintf(tperrnoS, "%d", tperrno);
- BT_ASSERT_MESSAGE(tperrnoS, cd == -1);
- free(tperrnoS);
- }
- userlogc((char*) "r = %d, tperrno = %d", r, tperrno);
- BT_ASSERT(r == tperrno);
- if(tperrno == 0) {
- BT_ASSERT(recvbuf[0] == '1');
- }
- tpfree(sendbuf);
- tpfree(recvbuf);
- return cd;
- }