⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pystaf.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2001                                              *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/#include "STAF.h"#include <Python.h>#include "STAFString.h"extern "C"{#if defined(STAF_OS_NAME_HPUX) && !defined(__ia64)    void _main();#endif/****************************************//*  Python Wrappers for libSTAF functions  *//****************************************/static PyObject * PySTAFRegister(PyObject *self, PyObject *argv);static PyObject * PySTAFSubmit(PyObject *self, PyObject *argv);static PyObject * PySTAFUnregister(PyObject *self, PyObject *argv);static PyObject * PySTAFAddPrivacyDelimiters(PyObject *self, PyObject *argv);static PyObject * PySTAFEscapePrivacyDelimiters(PyObject *self, PyObject *argv);static PyObject * PySTAFMaskPrivateData(PyObject *self, PyObject *argv);static PyObject * PySTAFRemovePrivacyDelimiters(PyObject *self, PyObject *argv);static PyMethodDef PYSTAF_Methods[] ={    { "STAFRegister", PySTAFRegister, METH_VARARGS, "Register with STAF" },    { "STAFSubmit", PySTAFSubmit, METH_VARARGS, "Submit a STAF request" },    { "STAFUnregister", PySTAFUnregister, METH_VARARGS, "Unregister with STAF" },    { "STAFAddPrivacyDelimiters", PySTAFAddPrivacyDelimiters,       METH_VARARGS, "Add Privacy Delimiters" },    { "STAFEscapePrivacyDelimiters", PySTAFEscapePrivacyDelimiters,       METH_VARARGS, "Escape Privacy Delimiters" },    { "STAFMaskPrivateData", PySTAFMaskPrivateData,       METH_VARARGS, "Mask Private Data" },    { "STAFRemovePrivacyDelimiters", PySTAFRemovePrivacyDelimiters,       METH_VARARGS, "Remove Privacy Delimiters" },    { 0, 0, 0, 0 }};/********************************************************************//* Initialization Procedure called when package is loaded in script *//********************************************************************/void initPYSTAF(void) {    #if defined(STAF_OS_NAME_HPUX) && !defined(__ia64)        _main();    #endif    PyObject *module = Py_InitModule("PYSTAF", PYSTAF_Methods);}/******************************************//* Implementation of Wrappers             *//******************************************/PyObject * PySTAFRegister(PyObject *self, PyObject *argv){    char *name = 0;    if (!PyArg_ParseTuple(argv, "s", &name)) return NULL;    STAFHandle_t handle = 0;    STAFRC_t rc = STAFRegister(name, &handle);    return Py_BuildValue("(ii)", rc, handle);}PyObject * PySTAFSubmit(PyObject *self, PyObject *argv){    static char empty_string[1] = { 0 };    STAFHandle_t handle = 0;    STAFSyncOption_t syncOption = kSTAFReqSync;    char *machine = 0;    char *service = 0;    char *request = 0;    unsigned int requestLength = 0;    if (!PyArg_ParseTuple(argv, "iisss#", &handle, &syncOption, &machine,                          &service, &request, &requestLength))    {        return NULL;    }    char *result = 0;    unsigned int resultLength = 0;    STAFRC_t rc;    Py_BEGIN_ALLOW_THREADS;    rc = STAFSubmit2(handle, syncOption, machine, service, request,                     requestLength, &result, &resultLength);    Py_END_ALLOW_THREADS;    char *result2 = (result == 0) ? empty_string : result;    PyObject *pyResult = Py_BuildValue("(is#)", rc, result2, resultLength);    STAFFree(handle, result);    return pyResult;}PyObject * PySTAFUnregister(PyObject *self, PyObject *argv){    STAFHandle_t handle = 0;    if (!PyArg_ParseTuple(argv, "i", &handle)) return NULL;    STAFRC_t rc = STAFUnRegister(handle);    return Py_BuildValue("i", rc);}static char sInfoBuffer[256] = { 0 };static int sInfoBufferInited = 0;char *STAFGetInformation(){   if (!sInfoBufferInited)   {       sprintf(sInfoBuffer, "%s STAF Python support library version 1.0",               #ifdef NDEBUG                   "Retail");               #else                   "Debug");               #endif       sInfoBufferInited = 1;   }   return sInfoBuffer;}PyObject * PySTAFAddPrivacyDelimiters(PyObject *self, PyObject *argv){    char *data = 0;    if (!PyArg_ParseTuple(argv, "s", &data)) return NULL;    // Need to add a null character at the end    STAFString result = STAFHandle::addPrivacyDelimiters(        STAFString(data)) + STAFString(kUTF8_NULL);        return Py_BuildValue("s", result.toCurrentCodePage()->buffer());}PyObject * PySTAFEscapePrivacyDelimiters(PyObject *self, PyObject *argv){    char *data = 0;    if (!PyArg_ParseTuple(argv, "s", &data)) return NULL;    // Need to add a null character at the end    STAFString result = STAFHandle::escapePrivacyDelimiters(        STAFString(data)) + STAFString(kUTF8_NULL);        return Py_BuildValue("s", result.toCurrentCodePage()->buffer());}PyObject * PySTAFMaskPrivateData(PyObject *self, PyObject *argv){    char *data = 0;    if (!PyArg_ParseTuple(argv, "s", &data)) return NULL;    // Need to add a null character at the end    STAFString result = STAFHandle::maskPrivateData(        STAFString(data)) + STAFString(kUTF8_NULL);        return Py_BuildValue("s", result.toCurrentCodePage()->buffer());}PyObject * PySTAFRemovePrivacyDelimiters(PyObject *self, PyObject *argv){    char *data = 0;    int numLevels = 0;    if (!PyArg_ParseTuple(argv, "si", &data, &numLevels)) return NULL;    // Need to add a null character at the end    STAFString result = STAFHandle::removePrivacyDelimiters(        STAFString(data), numLevels) + STAFString(kUTF8_NULL);        return Py_BuildValue("s", result.toCurrentCodePage()->buffer());}} // end extern "C"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -