Commit d8f2680b by 李定达

1.修复string返回null的bug;2.修复多商品不循环输出bug;3.添加测试用例

parent da6f455d
No preview for this file type
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
using namespace rapidxml; using namespace rapidxml;
using namespace rapidjson; using namespace rapidjson;
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
PrintLib::PrintLib(void) PrintLib::PrintLib(void)
{ {
...@@ -118,7 +119,11 @@ void PrintLib::_PrintMultLine(rapidxml::xml_node<> *node,rapidjson::Document &js ...@@ -118,7 +119,11 @@ void PrintLib::_PrintMultLine(rapidxml::xml_node<> *node,rapidjson::Document &js
bool ret = _GetJsonArryNode(fieldName,jsonDoc,childJson); bool ret = _GetJsonArryNode(fieldName,jsonDoc,childJson);
if (!ret) if (!ret)
{ {
_XMLiterate(node,jsonDoc,childJson); for (SizeType i = 0; i < childJson.Size(); i++)
{
rapidjson::Value& temp= childJson[i];
_XMLiterate(node,jsonDoc,temp);
}
} }
else else
{ {
...@@ -879,6 +884,7 @@ void PrintLib::_PrintData( const LinePrintArguments& arguments ) ...@@ -879,6 +884,7 @@ void PrintLib::_PrintData( const LinePrintArguments& arguments )
memset(temchar, 0, 2048); memset(temchar, 0, 2048);
strcpy(temchar,text.c_str()); strcpy(temchar,text.c_str());
if(!printType.compare("Text")){ if(!printType.compare("Text")){
...@@ -904,6 +910,27 @@ void PrintLib::_PrintData( const LinePrintArguments& arguments ) ...@@ -904,6 +910,27 @@ void PrintLib::_PrintData( const LinePrintArguments& arguments )
} }
//void GetProcPath(std::string &str)
//{
// int curPos;
// char pathBuf[MAX_PATH] = { 0 };
//
// GetModuleFileName((HMODULE)&__ImageBase, pathBuf, MAX_PATH);
//
//
// curPos = strlen(pathBuf) - 1;
//
// while('\\' != pathBuf[curPos])
// {
// curPos--;
// }
//
// curPos++;
//
// pathBuf[curPos] = '\0';
// str = std::string(pathBuf);
//}
std::string PrintLib::_GetMathValue(rapidjson::Document &jsonDoc,const std::string &toMatch,rapidjson::Value & childNode) std::string PrintLib::_GetMathValue(rapidjson::Document &jsonDoc,const std::string &toMatch,rapidjson::Value & childNode)
{ {
if (jsonDoc.HasMember(toMatch.c_str())) //一级就可以找到 if (jsonDoc.HasMember(toMatch.c_str())) //一级就可以找到
...@@ -966,7 +993,7 @@ std::string PrintLib::_JsonValueDivide(rapidjson::Value &value) ...@@ -966,7 +993,7 @@ std::string PrintLib::_JsonValueDivide(rapidjson::Value &value)
return value.GetString(); return value.GetString();
} }
return NULL; return string("");
} }
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "rapidjson/writer.h" #include "rapidjson/writer.h"
#include "rapidjson/memorystream.h" #include "rapidjson/memorystream.h"
struct LinePrintArguments{ struct LinePrintArguments{
// 字体种类 // 字体种类
int fontType; int fontType;
...@@ -67,6 +65,8 @@ public: ...@@ -67,6 +65,8 @@ public:
//bool DoPrint(std::string prtname, std::string pagewid, std::string jsonStr, std::string xmlStr, std::string &error); //bool DoPrint(std::string prtname, std::string pagewid, std::string jsonStr, std::string xmlStr, std::string &error);
//bool DoTestPrint(std::string prtname, std::string pagewid, std::string jsonStr, std::string xmlStr, std::string &error); //bool DoTestPrint(std::string prtname, std::string pagewid, std::string jsonStr, std::string xmlStr, std::string &error);
//static void GetProcPath(std::string &str);
private: private:
//typedef bool ( *OpenPrint)( void); //typedef bool ( *OpenPrint)( void);
//typedef void ( *InitPrinter)( char str[]); //typedef void ( *InitPrinter)( char str[]);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "fmlog.h" #include "fmlog.h"
#include "PrtSetConf.h" #include "PrtSetConf.h"
#include "filesystem.h"
#include <vector> #include <vector>
using std::vector; using std::vector;
...@@ -1807,9 +1809,30 @@ void FreeLine() ...@@ -1807,9 +1809,30 @@ void FreeLine()
//以下均为包装转换接口; //以下均为包装转换接口;
bool f_PrintBmp(char pszPath[], int nOrgx, int nMode,int alignMode) bool f_PrintBmp(char pszPath[], int nOrgx, int nMode,int alignMode)
{ {
string path;
FileSys::GetProcPath(path);
char tmppath[MAX_PATH+10] = {0};
if(strlen(pszPath) + path.size() > MAX_PATH)
return false;
if(string(pszPath).find(":") == string::npos)
{
strcpy(tmppath, path.c_str());
strcpy(tmppath+strlen(tmppath), "prtinfo\\");
strcpy(tmppath+strlen(tmppath), pszPath);
}
else
{
strcpy(tmppath, pszPath);
}
LOG() << "图片路径:" << pszPath << alignMode; LOG() << "图片路径:" << pszPath << alignMode;
LOG() << "图片完整路径:" << tmppath;
VC_POS_S_SetAlignMode(alignMode); VC_POS_S_SetAlignMode(alignMode);
int result = VC_POS_S_DownloadAndPrintBmp(pszPath,nOrgx,nMode); int result = VC_POS_S_DownloadAndPrintBmp(tmppath,nOrgx,nMode);
if(result == POS_SUCCESS ) if(result == POS_SUCCESS )
{ {
LOG() << "打印图片成功"; LOG() << "打印图片成功";
......
#include <iostream>
#include <fstream>
#include <cassert>
#include <string>
#include "PrtSetConf.h" #include "PrtSetConf.h"
#include "prtlib.h" #include "prtlib.h"
#include <Windows.h> #include <Windows.h>
using namespace std;
void testGetPrintInfo() void testGetPrintInfo()
{ {
PrintInfo info; PrintInfo info;
...@@ -144,15 +150,32 @@ void testPrt() ...@@ -144,15 +150,32 @@ void testPrt()
#include "PrintLib.h" #include "PrintLib.h"
void DoPrintWithXmls(char *prtStr, char *orderStr, char*xmlStr, char* error) void DoPrintWithXmls(char *prtStr, char *orderStr, char*xmlStr, char* error)
{ {
std::string prt = prtStr; string prt = prtStr;
std::string order = orderStr; string order = orderStr;
std::string xml = xmlStr; string xml = xmlStr;
std::string err = error; string err = error;
PrintLib::GetInstance().DoPrint(prt,order,xml,err); PrintLib::GetInstance().DoPrint(prt,order,xml,err);
} }
void GetFileBuf(char *des, string filename)
{
fstream infile;
infile.open(filename.data());
assert(infile.is_open());
string s;
while(getline(infile,s))
{
strcpy(des + strlen(des), s.data());
}
infile.close();
//cout << "filename : " << filename;
//cout << "des : " << des;
}
int main() int main()
{ {
...@@ -170,13 +193,24 @@ int main() ...@@ -170,13 +193,24 @@ int main()
// //testPrt(); // //testPrt();
//} //}
LoadAddress();
//Unloaddll(); //Unloaddll();
//char xmlstr[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ticket type=\"OrderPrint\" typeCode=\"1\">\n<line printType=\"Text\" text=\"0001非码测试单\" codeType=\"1\" fontType=\"1\" fontStyle=\"1\" width=\"2\" height=\"2\" leftMargin=\"0\" AlignMode=\"1\"/>\n</ticket>"; //char xmlstr[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ticket type=\"OrderPrint\" typeCode=\"1\">\n<line printType=\"Text\" text=\"0001非码测试单\" codeType=\"1\" fontType=\"1\" fontStyle=\"1\" width=\"2\" height=\"2\" leftMargin=\"0\" AlignMode=\"1\"/>\n</ticket>";
char xmlstr[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ticket type = \"OrderPrint\" typeCode = \"1\"><line printType=\"Text\" text=\"%1Bulabula%2\" fontType=\"1\" fontStyle=\"1\" width=\"1\" height=\"1\" leftMargin=\"0\" AlignMode=\"0\"><math index=\"1\" content=\"order_title\" /><math index=\"2\" content=\"order_index\" /></line></ticket>"; //char xmlstr[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ticket type = \"OrderPrint\" typeCode = \"1\"><line printType=\"Text\" text=\"%1Bulabula%2\" fontType=\"1\" fontStyle=\"1\" width=\"1\" height=\"1\" leftMargin=\"0\" AlignMode=\"0\"><math index=\"1\" content=\"order_title\" /><math index=\"2\" content=\"order_index\" /></line></ticket>";
char conf[] = "{\"name\":\"U80(P)\",\"PaperWidth\":\"56\",\"type\":4}"; char conf[] = "{\"ip\":\"172.16.1.252\",\"PaperWidth\":\"56\",\"type\":3}";
char order[] = "{\"order_title\":\"AAAA\",\"order_index\":\"0001\"}"; //char order[] = "{\"order_title\":\"AAAA\",\"order_index\":\"0001\"}";
char err[1024] = {}; char err[1024] = {};
char xmlstr[25600] = {0};
char order[25600] = {0};
string xmlfilename = "D:\\gitcode\\prtlab\\PrtLib\\Debug\\xml.txt";
string jsonfilename = "D:\\gitcode\\prtlab\\PrtLib\\Debug\\json.txt";
GetFileBuf(xmlstr, xmlfilename);
GetFileBuf(order, jsonfilename);
DoPrintWithXmls(conf, order, xmlstr, err); DoPrintWithXmls(conf, order, xmlstr, err);
system("pause"); system("pause");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment