Debian Codegraph @

src/lw/tests/MOCK_LWLMPrintEnvironment.cpp

raw
1 // -*- C++ -*-
2 // $Id: MOCK_LWLMPrintEnvironment.cpp 15962 2011-09-02 14:45:00Z pineichen $
3
4 // DYMO LabelWriter Drivers
5 // Copyright (C) 2008 Sanford L.P.
6
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 #include "MOCK_LWLMPrintEnvironment.h"
22 #include "../LabelWriterDriver.h"
23 #include <assert.h>
24
25 static const byte TOF_BIT = 0x02;
26 static const byte ROLL_CHANGED_BIT = 0x08;
27 static const byte PAPER_OUT_BIT = 0x20;
28 static const byte PAPER_FEED_BIT = 0x40;
29 static const byte ERROR_BIT = 0x80;
30
31
32 MockLWLMPrintEnvironment::MockLWLMPrintEnvironment(): Mode_()
33 {
34 Mode_.push_back(mtTOF);
35 }
36
37 void
38 MockLWLMPrintEnvironment::WriteData(const buffer_t& Data)
39 {
40 // printf("MockLWLMPrintEnvironment::WriteData()");
41
42 // don't store request status requests
43 if (Data != CLabelWriterDriver::GetRequestStatusCommand())
44 MockPrintEnvironment::WriteData(Data);
45 }
46
47 void
48 MockLWLMPrintEnvironment::ReadData(buffer_t& Data)
49 {
50 //printf("MockLWLMPrintEnvironment::ReadData()");
51
52 Data.clear();
53
54 mode_t Mode = mtTOF;
55
56 if (Mode_.size() > 1)
57 {
58 Mode = Mode_.back();
59 Mode_.pop_back();
60 }
61 else
62 Mode = Mode_.back();
63
64 switch (Mode)
65 {
66 case mtTOF:
67 Data.push_back(TOF_BIT);
68 break;
69 case mtPaperOut:
70 Data.push_back(ERROR_BIT | PAPER_OUT_BIT);
71 break;
72 case mtRollChanged:
73 Data.push_back(TOF_BIT | ROLL_CHANGED_BIT);
74 break;
75 case mtNotTOF:
76 Data.push_back(0);
77 break;
78 case mtFailed:
79 break;
80 default:
81 assert(0);
82 }
83 }
84
85 IPrintEnvironment::job_status_t
86 MockLWLMPrintEnvironment::GetJobStatus()
87 {
88 return jsOK;
89 }
90
91
92 void
93 MockLWLMPrintEnvironment::SetJobStatus(job_status_t JobStatus)
94 {
95 switch (JobStatus)
96 {
97 case jsOK:
98 //fprintf(stderr, "INFO: continue printing.\n");
99 break;
100 case jsPaperOut:
101 //fprintf(stderr, "INFO: paper out.\n");
102 break;
103 case jsError:
104 //fprintf(stderr, "INFO: printing error.\n");
105 break;
106 default:
107 assert(0);
108 }
109 }
110
111
112 void
113 MockLWLMPrintEnvironment::SetMode(mode_t Mode)
114 {
115 Mode_.clear();
116 Mode_.push_back(Mode);
117 }
118
119 void
120 MockLWLMPrintEnvironment::PushMode(mode_t Mode, size_t Count)
121 {
122 for (size_t i = 0; i < Count; ++i)
123 Mode_.push_back(Mode);
124 }
125
126
127 /*
128 * End of "$Id: MOCK_LWLMPrintEnvironment.cpp 15962 2011-09-02 14:45:00Z pineichen $".
129 */
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145