1 #include "stdafx.h"
2 #include "CTest.h"
3 #include "InternetCommon.h"
4 #include "COSUPlayerHelper.h"
5 #include "RegFileRelate.h"
6 #include "MediaLibHelper.h"
7 #include "IniHelper.h"
8 #include "MusicPlayerCmdHelper.h"
9 #include "MessageDlg.h"
10 #include "TagSelBaseDlg.h"
11 #include "TagLibHelper.h"
12 #include "Player.h"
13 #include "CueFile.h"
14 #include "MusicPlayer2.h"
15
CTest()16 CTest::CTest()
17 {
18 }
19
20
~CTest()21 CTest::~CTest()
22 {
23 }
24
Test()25 void CTest::Test()
26 {
27 //TestStringMatch();
28 //TestCrash();
29 //TestShortCut();
30 //TestCommon();
31 //TestOSUFile();
32 //TestReg();
33 //TestMediaLib();
34 //TestAudioTag();
35
36 //Time time(1000, 64, 1024);
37
38 //int a = sizeof(wstring);
39
40 //CString info;
41 //info.Format(_T("sizeof(SongInfo)=%d\nsizeof(Time)=%d"), sizeof(SongInfo), sizeof(Time));
42 //AfxMessageBox(info);
43
44 //TestImageResize();
45 //TestCrash();
46 //TestTagParse();
47 //TestStringSplit();
48
49 //int size = sizeof(SongInfo);
50 //MessageBox(theApp.m_pMainWnd->GetSafeHwnd(), std::to_wstring(size).c_str(), NULL, MB_OK);
51
52 //TestRating();
53
54 //TestCueSave();
55 //TestFilePathHelper();
56 //TestStringToInt();
57 TestChinesePingyinMatch();
58 }
59
TestStringMatch()60 void CTest::TestStringMatch()
61 {
62 double res = CInternetCommon::StringSimilarDegree_LD(L"12345a", L"12345A");
63 double res1 = CInternetCommon::StringSimilarDegree_LD(L"12345A", L"12345a");
64 double res3 = CInternetCommon::StringSimilarDegree_LD(L"12345a", L"12345b");
65
66
67 double res4 = CInternetCommon::StringSimilarDegree_LD(L"12345a", L"1234a5");
68 double res5 = CInternetCommon::StringSimilarDegree_LD(L"12345a", L"1234A5");
69
70 int a = 0;
71 }
72
TestCrash()73 void CTest::TestCrash()
74 {
75 CString* pStr = nullptr;
76 int a = pStr->GetLength();
77 printf("%d", a);
78 }
79
TestShortCut()80 void CTest::TestShortCut()
81 {
82 int rtn = CCommon::CreateFileShortcut(L"D:\\Temp",
83 L"D:\\Program Files\\MusicPlayer2\\MusicPlayer2.exe",
84 NULL,
85 L"D:\\Program Files\\MusicPlayer2",
86 0,
87 NULL,
88 1,
89 L"-play_pause",
90 2
91 );
92 int a = 0;
93 }
94
TestCommon()95 void CTest::TestCommon()
96 {
97 //int b = CCommon::IconSizeNormalize(30);
98 //int a = 0;
99
100 //bool rtn = COSUPlayerHelper::IsOsuFolder(L"D:\\BaiduNetdiskDownload\\Songs/");
101
102 //vector<SongInfo> songs;
103 //COSUPlayerHelper::GetOSUAudioFiles(L"D:\\BaiduNetdiskDownload\\Songs\\", songs);
104 //if (!songs.empty())
105 // COSUPlayerHelper::GetOSUAudioTitleArtist(songs[0]);
106
107 //CCommon::CreateDir(L"D:\\Temp\\Folder\\");
108
109 //wstring rtn = CCommon::FileRename(L"D:\\Temp\\无标题.txt", L"无标题1");
110
111 //wstring str = L"!ABC!,!233!,!DEF!";
112 //std::vector<wstring> result;
113 //CCommon::StringSplit(str, L"!,!", result, false);
114
115 //{
116 // vector<wstring> string_list{ L"abcde", L"233333", L"39485skdj" };
117 // CIniHelper ini{ L"D:\\Temp\\test.ini" };
118 // ini.WriteStringList(L"config", L"test", string_list);
119 // ini.Save();
120 //}
121
122 //{
123 // vector<wstring> string_results;
124 // CIniHelper ini{ L"D:\\Temp\\test.ini" };
125 // ini.GetStringList(L"config", L"test", string_results, vector<wstring>{L"567"});
126 //}
127
128 //CMusicPlayerCmdHelper helper;
129 //helper.UpdateMediaLib();
130
131 //bool b = CCommon::IsPath(L"C:\\dfg\\:89");
132
133 //WORD value = 0x2f;
134 //bool b = CCommon::GetNumberBit(value, 4);
135
136 //CCommon::SetNumberBit(value, 4, true);
137 //CCommon::SetNumberBit(value, 4, false);
138
139 //unsigned __int64 t = CCommon::GetFileLastModified(L"D:\\Temp\\Introduction.txt");
140 //unsigned __int64 t1 = CCommon::GetFileLastModified(L"D:\\Temp\\新建文本文档.jpg");
141 //bool b = t > t1;
142
143 //int r = CCommon::Random(0, 3);
144
145 //wstring dir = L"D:";
146 //wstring path = L"C:\\r\\1.txt";
147 //wstring result = CCommon::RelativePathToAbsolutePath(path, dir);
148
149 int a = 0;
150 }
151
TestOSUFile()152 void CTest::TestOSUFile()
153 {
154 COSUFile osu_file{ L"D:\\Program Files\\osu!\\Songs\\66385 u's - Snow halation\\u's - Snow halation (blissfulyoshi) [Insane].osu" };
155 wstring file_name = osu_file.GetAudioFileName();
156 int a = 0;
157
158 }
159
TestReg()160 void CTest::TestReg()
161 {
162 CRegFileRelate reg;
163 //bool rtn = reg.AddFileTypeRelate(_T(".wma"), 46);
164 //bool rtn = reg.DeleteFileTypeRelate(_T(".test"));
165 std::vector<wstring> exts;
166 reg.GetAllRelatedExtensions(exts);
167 int a = 0;
168 }
169
TestMediaLib()170 void CTest::TestMediaLib()
171 {
172 CMediaClassifier media_lib(CMediaClassifier::CT_TYPE);
173 media_lib.ClassifyMedia();
174 int a = 0;
175 }
176
TestAudioTag()177 void CTest::TestAudioTag()
178 {
179 //wstring file_path = L"D:\\Temp\\test.mp3";
180 //HSTREAM hStream = BASS_StreamCreateFile(FALSE, file_path.c_str(), 0, 0, BASS_SAMPLE_FLOAT);
181 //SongInfo song_info;
182 // song_info.file_path = file_path;
183 //CAudioTag audio_tag(song_info, hStream);
184 //audio_tag.GetAudioTag();
185 //wstring str_lyric = audio_tag.GetAudioLyric();
186 //BASS_StreamFree(hStream);
187
188 //wstring result = CTagLibHelper::GetApeCue(L"D:\\Temp\\内嵌cue测试\\Various - 世界名曲鉴赏 珍藏版.ape");
189
190 std::map<wstring, wstring> propertyis;
191 SongInfo song_info;
192 song_info.file_path = L"D:\\Temp\\TRACK.04.wav";
193 CAudioTag audio_tag(song_info);
194 audio_tag.GetAudioTagPropertyMap(propertyis);
195
196 int a = 0;
197 }
198
TestImageResize()199 void CTest::TestImageResize()
200 {
201 CDrawCommon::ImageResize(L"D:\\Temp\\83538667_p0.png", L"D:\\Temp\\test_dest.jpg", 512, IT_JPG);
202 }
203
TestCrashDlg()204 void CTest::TestCrashDlg()
205 {
206 //显示错误信息对话框
207 // 待重写(做独立的crash对话框)
208 }
209
TestTagParse()210 void CTest::TestTagParse()
211 {
212 SongInfo song;
213 CTagSelBaseDlg::GetTagFromFileName(CTagSelBaseDlg::FORMULAR_YEAR + L"-" + CTagSelBaseDlg::FORMULAR_ARTIST + L"FFFF" + CTagSelBaseDlg::FORMULAR_TITLE, L"666-744FFFF23", song);
214
215 int a = 0;
216 }
217
TestStringSplit()218 void CTest::TestStringSplit()
219 {
220 vector<wstring> result;
221 CCommon::StringSplitWithSeparators(L"1-223&**34@@#YYF%%%%^SD", vector<wstring>{L"-", L"&**", L"@@#", L"%%%%^"}, result);
222 int a = 0;
223 }
224
TestRating()225 void CTest::TestRating()
226 {
227 int rate = CTagLibHelper::GetMepgRating(CPlayer::GetInstance().GetCurrentSongInfo().file_path);
228 //CTagLibHelper::WriteMpegRating(CPlayer::GetInstance().GetCurrentSongInfo().file_path, 2);
229 int a = 0;
230 }
231
TestCueSave()232 void CTest::TestCueSave()
233 {
234 CCueFile cue_file(L"C:\\Temp\\cue_test\\1979.cue");
235 cue_file.Save(L"C:\\Temp\\cue_test\\1979_1.cue");
236 }
237
TestFilePathHelper()238 void CTest::TestFilePathHelper()
239 {
240 CFilePathHelper helper(L"C:\\abc.d\\efg");
241 wstring file_name = helper.GetFileName();
242 wstring file_extension = helper.GetFileExtension();
243 wstring file_name_whthout_extension = helper.GetFileNameWithoutExtension();
244 wstring file_dir = helper.GetDir();
245 wstring folder_name = helper.GetFolderName();
246 ASSERT(file_name == L"efg");
247 ASSERT(file_extension.empty());
248 ASSERT(file_name_whthout_extension == L"efg");
249 ASSERT(file_dir == L"C:\\abc.d\\");
250 ASSERT(folder_name == L"abc.d");
251 }
252
TestStringToInt()253 void CTest::TestStringToInt()
254 {
255 wstring str1 = L"abc0234ttyyhh";
256 int n1 = CCommon::StringToInt(str1);
257 ASSERT(n1 == 234);
258 wstring str2 = L"abc056";
259 int n2 = CCommon::StringToInt(str2);
260 ASSERT(n2 == 56);
261 wstring str3 = L"876rrtyhfg345hg";
262 int n3 = CCommon::StringToInt(str3);
263 ASSERT(n3 == 876);
264 wstring str4 = L"sdfoeoirglksf6";
265 int n4 = CCommon::StringToInt(str4);
266 ASSERT(n4 == 6);
267 }
268
TestChinesePingyinMatch()269 void CTest::TestChinesePingyinMatch()
270 {
271 ASSERT(theApp.m_chinese_pingyin_res.IsStringMatchWithPingyin(L"nh", L"你好世界"));
272 ASSERT(theApp.m_chinese_pingyin_res.IsStringMatchWithPingyin(L"nhsj", L"你好世界"));
273 ASSERT(theApp.m_chinese_pingyin_res.IsStringMatchWithPingyin(L"nihaoshijie", L"你好世界"));
274 ASSERT(!theApp.m_chinese_pingyin_res.IsStringMatchWithPingyin(L"nh", L"你世界"));
275 ASSERT(theApp.m_chinese_pingyin_res.IsStringMatchWithPingyin(L"cxqd", L"春夏秋冬"));
276 }
277