Skip to content

Commit ed7586d

Browse files
committed
CPP: Add a combined test for the combined query.
1 parent ed53aef commit ed7586d

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class EraInfo
2+
{
3+
public:
4+
EraInfo() {
5+
6+
};
7+
8+
EraInfo(int year, int month, int day) {
9+
10+
};
11+
12+
EraInfo(int Era, int foo, int year, int month, int day, const wchar_t * eraName)
13+
{
14+
15+
}
16+
17+
static EraInfo * EraInfoFromDate(int Era, int foo, int year, int month, int day, wchar_t * eraName)
18+
{
19+
return new EraInfo(Era, foo, year, month, day, eraName);
20+
}
21+
};
22+
23+
int Main()
24+
{
25+
26+
// BAD: constructor creating a EraInfo with exact Heisei era start date
27+
EraInfo * pDateTimeUtil = new EraInfo(1989, 1, 8);
28+
29+
// BAD: constructor creating a EraInfo with exact Heisei era start date
30+
EraInfo * pDateTimeUtil1 = new EraInfo(1, 2, 1989, 1, 8, L"\u5e73\u6210");
31+
32+
// Good: constructor creating a EraInfo with another date
33+
EraInfo * pDateTimeUtil2 = new EraInfo(1, 2, 1900, 1, 1, L"foo");
34+
35+
// BAD: method call passing exact Haisei era start date as parameters
36+
EraInfo * pDateTimeUtil3 = EraInfo::EraInfoFromDate(1, 2, 1989, 1, 8, L"\u5e73\u6210");
37+
38+
// GOOD: method call with the same parameters in a different order (we only track year, month, day)
39+
EraInfo * pDateTimeUtil4 = EraInfo::EraInfoFromDate(1, 2, 8, 1, 1989, L"\u5e73\u6210");
40+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| ConstructorOrMethodWithExactDate.cpp:27:31:27:53 | call to EraInfo | Call that appears to have hard-coded Japanese era start date as parameter. |
2+
| ConstructorOrMethodWithExactDate.cpp:30:32:30:77 | call to EraInfo | Call that appears to have hard-coded Japanese era start date as parameter. |
3+
| ConstructorOrMethodWithExactDate.cpp:36:32:36:55 | call to EraInfoFromDate | Call that appears to have hard-coded Japanese era start date as parameter. |
4+
| StructWithExactDate.cpp:31:13:31:19 | tm_year | A time struct that is initialized with exact Japanese calendar era start date. |
5+
| StructWithExactDate.cpp:46:8:46:12 | wYear | A time struct that is initialized with exact Japanese calendar era start date. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Best Practices/Magic Constants/JapaneseEraDate.ql
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
typedef unsigned short WORD;
2+
3+
struct tm
4+
{
5+
int tm_sec; // seconds after the minute - [0, 60] including leap second
6+
int tm_min; // minutes after the hour - [0, 59]
7+
int tm_hour; // hours since midnight - [0, 23]
8+
int tm_mday; // day of the month - [1, 31]
9+
int tm_mon; // months since January - [0, 11]
10+
int tm_year; // years since 1900
11+
int tm_wday; // days since Sunday - [0, 6]
12+
int tm_yday; // days since January 1 - [0, 365]
13+
int tm_isdst; // daylight savings time flag
14+
};
15+
16+
typedef struct _SYSTEMTIME {
17+
WORD wYear;
18+
WORD wMonth;
19+
WORD wDayOfWeek;
20+
WORD wDay;
21+
WORD wHour;
22+
WORD wMinute;
23+
WORD wSecond;
24+
WORD wMilliseconds;
25+
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
26+
27+
int main()
28+
{
29+
// BAD: Creation of tm stuct corresponding to the beginning of Heisei era
30+
tm *timeTm = new tm();
31+
timeTm->tm_year = 1989;
32+
timeTm->tm_mon = 1;
33+
timeTm->tm_mday = 8;
34+
35+
36+
// GOOD: Creation of tm stuct with different date
37+
tm *timeTm1 = new tm();
38+
timeTm1->tm_year = 1988;
39+
timeTm1->tm_mon = 1;
40+
timeTm1->tm_mday = 1;
41+
42+
// BAD: Creation of SYSTEMTIME stuct corresponding to the beginning of Heisei era
43+
SYSTEMTIME st;
44+
st.wDay = 8;
45+
st.wMonth = 1;
46+
st.wYear = 1989;
47+
48+
49+
// GOOD: Creation of SYSTEMTIME stuct with a different date
50+
SYSTEMTIME st1;
51+
st1.wDay = 1;
52+
st1.wMonth = 1;
53+
st1.wYear = 1990;
54+
55+
return 0;
56+
}
57+

0 commit comments

Comments
 (0)