Skip to content

Commit df09a30

Browse files
committed
add ci
Check format with clang-format. Check compile.
1 parent ef21232 commit df09a30

File tree

7 files changed

+240
-41
lines changed

7 files changed

+240
-41
lines changed

.clang-format

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# clang-format >= 15
2+
---
3+
Language: Cpp
4+
AccessModifierOffset: -4
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: DontAlign
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
AllowShortBlocksOnASingleLine: Never
13+
AllowShortCaseLabelsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: Inline
15+
AllowShortIfStatementsOnASingleLine: false
16+
AllowShortLoopsOnASingleLine: false
17+
AlwaysBreakAfterReturnType: None
18+
AlwaysBreakBeforeMultilineStrings: false
19+
AlwaysBreakTemplateDeclarations: Yes
20+
BinPackArguments: false
21+
BinPackParameters: false
22+
BraceWrapping:
23+
AfterClass: true
24+
AfterControlStatement: Never
25+
AfterEnum: false
26+
AfterFunction: true
27+
AfterNamespace: false
28+
AfterObjCDeclaration: false
29+
AfterStruct: true
30+
AfterUnion: false
31+
BeforeCatch: false
32+
BeforeElse: false
33+
IndentBraces: false
34+
SplitEmptyFunction: false
35+
SplitEmptyRecord: false
36+
SplitEmptyNamespace: false
37+
BreakBeforeBinaryOperators: All
38+
BreakBeforeBraces: Custom
39+
BreakBeforeInheritanceComma: false
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializersBeforeComma: false
42+
BreakConstructorInitializers: BeforeComma
43+
BreakAfterJavaFieldAnnotations: false
44+
BreakStringLiterals: true
45+
ColumnLimit: 100
46+
CommentPragmas: '^ IWYU pragma:'
47+
CompactNamespaces: false
48+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
49+
ConstructorInitializerIndentWidth: 4
50+
ContinuationIndentWidth: 4
51+
Cpp11BracedListStyle: true
52+
DerivePointerAlignment: false
53+
DisableFormat: false
54+
ExperimentalAutoDetectBinPacking: false
55+
FixNamespaceComments: true
56+
ForEachMacros:
57+
- forever # avoids { wrapped to next line
58+
- foreach
59+
- Q_FOREACH
60+
- BOOST_FOREACH
61+
IncludeCategories:
62+
- Regex: '^<Q.*'
63+
Priority: 200
64+
IncludeIsMainRegex: '(Test)?$'
65+
IndentCaseLabels: false
66+
IndentWidth: 4
67+
IndentWrappedFunctionNames: false
68+
InsertBraces: false
69+
JavaScriptQuotes: Leave
70+
JavaScriptWrapImports: true
71+
KeepEmptyLinesAtTheStartOfBlocks: false
72+
# Do not add QT_BEGIN_NAMESPACE/QT_END_NAMESPACE as this will indent lines in between.
73+
MacroBlockBegin: ""
74+
MacroBlockEnd: ""
75+
MaxEmptyLinesToKeep: 1
76+
NamespaceIndentation: None
77+
ObjCBlockIndentWidth: 4
78+
ObjCSpaceAfterProperty: false
79+
ObjCSpaceBeforeProtocolList: true
80+
PenaltyBreakAssignment: 88
81+
PenaltyBreakBeforeFirstCallParameter: 300
82+
PenaltyBreakComment: 500
83+
PenaltyBreakFirstLessLess: 400
84+
PenaltyBreakString: 600
85+
PenaltyExcessCharacter: 50
86+
PenaltyReturnTypeOnItsOwnLine: 300
87+
PointerAlignment: Right
88+
ReflowComments: false
89+
SortIncludes: CaseSensitive
90+
SortUsingDeclarations: true
91+
SpaceAfterCStyleCast: true
92+
SpaceAfterTemplateKeyword: false
93+
SpaceBeforeAssignmentOperators: true
94+
SpaceBeforeParens: ControlStatements
95+
SpaceInEmptyParentheses: false
96+
SpacesBeforeTrailingComments: 1
97+
SpacesInAngles: false
98+
SpacesInContainerLiterals: false
99+
SpacesInCStyleCastParentheses: false
100+
SpacesInParentheses: false
101+
SpacesInSquareBrackets: false
102+
Standard: c++11
103+
TabWidth: 4
104+
UseTab: Never

.github/workflows/ci.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Copyright 2023 The Tongsuo Project Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License 2.0 (the "License"). You may not use
4+
# this file except in compliance with the License. You can obtain a copy
5+
# in the file LICENSE in the source distribution or at
6+
# https://github.com/Tongsuo-Project/tsapp/blob/main/LICENSE
7+
8+
name: GitHub CI
9+
10+
on: [pull_request, push]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
check-format:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: install dependency
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install clang-format-15
23+
24+
- uses: actions/checkout@v3
25+
- name: check format
26+
run: |
27+
clang-format-15 --Werror --dry-run *.cpp *.h
28+
29+
build-on-linux:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: checkout tongsuo
33+
uses: actions/checkout@v3
34+
with:
35+
repository: Tongsuo-Project/Tongsuo
36+
path: Tongsuo
37+
- name: build Tongsuo
38+
working-directory: ./Tongsuo
39+
run: |
40+
./config --banner=Configured --prefix=${RUNNER_TEMP}/tongsuo enable-ntls
41+
make -s -j4
42+
make install
43+
44+
- uses: actions/checkout@v3
45+
- name: install QT
46+
uses: jurplel/install-qt-action@v3
47+
with:
48+
version: 6.2.4
49+
50+
- name: build tsapp
51+
run: |
52+
TONGSUO_HOME=${RUNNER_TEMP}/tongsuo PREFIX=${RUNNER_TEMP}/tsapp qmake
53+
make -s -j4
54+
make install
55+
56+
build-on-windows:
57+
runs-on: windows-latest
58+
steps:
59+
- uses: ilammy/msvc-dev-cmd@v1
60+
with:
61+
arch: win64
62+
- uses: ilammy/setup-nasm@v1
63+
with:
64+
platform: win64
65+
- uses: shogo82148/actions-setup-perl@v1
66+
- name: checkout tongsuo
67+
uses: actions/checkout@v3
68+
with:
69+
repository: Tongsuo-Project/Tongsuo
70+
path: Tongsuo
71+
72+
- name: build Tongsuo
73+
shell: cmd
74+
working-directory: ./Tongsuo
75+
run: |
76+
mkdir _build
77+
pushd _build
78+
perl ..\Configure no-makedepend no-shared enable-ntls VC-WIN64A --prefix=%RUNNER_TEMP%\tongsuo
79+
nmake /S
80+
nmake install_sw
81+
popd
82+
83+
- uses: actions/checkout@v3
84+
- name: install QT
85+
uses: jurplel/install-qt-action@v3
86+
with:
87+
version: 6.2.4
88+
89+
- name: build tsapp
90+
shell: cmd
91+
run: |
92+
set TONGSUO_HOME=%RUNNER_TEMP%\tongsuo
93+
set PREFIX=%RUNNER_TEMP%\tsapp
94+
qmake
95+
nmake /S
96+
nmake install
97+
98+
- name: debug
99+
if: ${{ failure() }}
100+
shell: cmd
101+
run: |
102+
type Makefile.Release

TongsuoToolbox_v01.pro

+8-13
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,18 @@ HEADERS += \
2020
randnum.h
2121

2222
# Default rules for deployment.
23-
qnx: target.path = /tmp/$${TARGET}/bin
24-
else: unix:!android: target.path = /opt/$${TARGET}/bin
23+
target.path = $$(PREFIX)
2524
!isEmpty(target.path): INSTALLS += target
2625

27-
INCLUDEPATH += Tongsuo\include
28-
INCLUDEPATH += Tongsuo\providers\implementations\include
29-
INCLUDEPATH += Tongsuo\providers\common\include
30-
INCLUDEPATH += Tongsuo\apps\include
31-
INCLUDEPATH += Tongsuo\crypto\include
26+
win32: LIBS += -ladvapi32 -lcrypt32 -lgdi32 -luser32 -lws2_32 -L$$(TONGSUO_HOME)/lib -llibcrypto
27+
else:unix: LIBS += -L$$(TONGSUO_HOME)/lib64 -lcrypto
3228

33-
win32: LIBS += -L$$PWD/Tongsuo/ -lcrypto
29+
INCLUDEPATH += $$(TONGSUO_HOME)/include
30+
DEPENDPATH += $$(TONGSUO_HOME)/include
3431

35-
INCLUDEPATH += $$PWD/Tongsuo
36-
DEPENDPATH += $$PWD/Tongsuo
37-
38-
win32:!win32-g++: PRE_TARGETDEPS += $$PWD/Tongsuo/crypto.lib
39-
else:win32-g++: PRE_TARGETDEPS += $$PWD/Tongsuo/libcrypto.a
32+
win32-g++: PRE_TARGETDEPS += $$(TONGSUO_HOME)/lib/libcrypto.lib.a
33+
else:win32:!win32-g++: PRE_TARGETDEPS += $$(TONGSUO_HOME)/lib/libcrypto.lib
34+
else:unix: PRE_TARGETDEPS += $$(TONGSUO_HOME)/lib64/libcrypto.a
4035

4136
FORMS += \
4237
home.ui \

home.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include "ui_home.h"
33
#include <QPainter>
44

5-
Home::Home(QWidget *parent) :
6-
QWidget(parent),
7-
ui(new Ui::Home)
5+
Home::Home(QWidget *parent)
6+
: QWidget(parent)
7+
, ui(new Ui::Home)
88
{
99
ui->setupUi(this);
1010
}
@@ -17,7 +17,8 @@ Home::~Home()
1717
void Home::paintEvent(QPaintEvent *event)
1818
{
1919
//重写自动执行
20-
QPixmap pixmap = QPixmap("://images/HomeBackground.png").scaled(this->size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
20+
QPixmap pixmap = QPixmap("://images/HomeBackground.png")
21+
.scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2122
QPainter painter(this);
22-
painter.drawPixmap(this->rect(), pixmap); //画家画图片
23+
painter.drawPixmap(this->rect(), pixmap); //画家画图片
2324
}

mainwindow.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ MainWindow::MainWindow(QWidget *parent)
3232
rdNum = new RandNum();
3333

3434
/* 左侧功能导航 */
35-
QList <QString>strListWidgetList;
36-
strListWidgetList<< "首页" << "随机数生成";
35+
QList<QString> strListWidgetList;
36+
strListWidgetList << "首页"
37+
<< "随机数生成";
3738

38-
for (int i = 0; i < 2; i++){
39+
for (int i = 0; i < 2; i++) {
3940
/* listWidget 插入项 */
40-
listWidget->insertItem( i,strListWidgetList[i]);
41+
listWidget->insertItem(i, strListWidgetList[i]);
4142
}
4243

4344
/* 子页面插入 */
@@ -56,10 +57,7 @@ MainWindow::MainWindow(QWidget *parent)
5657
widget->setLayout(hBoxLayout);
5758

5859
/* 利用 listWidget 的信号函数 currentRowChanged()与槽函数 setCurrentIndex()进行信号与槽连接*/
59-
connect(listWidget, SIGNAL(currentRowChanged(int)),
60-
stackedWidget, SLOT(setCurrentIndex(int)));
60+
connect(listWidget, SIGNAL(currentRowChanged(int)), stackedWidget, SLOT(setCurrentIndex(int)));
6161
}
6262

63-
MainWindow::~MainWindow()
64-
{
65-
}
63+
MainWindow::~MainWindow() {}

mainwindow.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifndef MAINWINDOW_H
22
#define MAINWINDOW_H
33

4-
#include <QMainWindow>
5-
#include <QStackedWidget>
6-
#include <QHBoxLayout>
7-
#include <QListWidget>
84
#include "home.h"
95
#include "randnum.h"
6+
#include <QHBoxLayout>
7+
#include <QListWidget>
8+
#include <QMainWindow>
9+
#include <QStackedWidget>
1010

1111
class MainWindow : public QMainWindow
1212
{
@@ -15,6 +15,7 @@ class MainWindow : public QMainWindow
1515
public:
1616
MainWindow(QWidget *parent = nullptr);
1717
~MainWindow();
18+
1819
private:
1920
/* widget 小部件 */
2021
QWidget *widget;
@@ -28,6 +29,5 @@ class MainWindow : public QMainWindow
2829
Home *tsHome;
2930
/* 功能1随机数生成界面 */
3031
RandNum *rdNum;
31-
3232
};
3333
#endif // MAINWINDOW_H

randnum.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "randnum.h"
22
#include "ui_randnum.h"
3+
#include <openssl/rand.h>
4+
#include <QIntValidator>
35
#include <QLineEdit>
4-
#include <QTextEdit>
56
#include <QString>
67
#include <QTextBrowser>
7-
#include <openssl/rand.h>
8-
#include <QIntValidator>
8+
#include <QTextEdit>
99

10-
RandNum::RandNum(QWidget *parent) :
11-
QWidget(parent),
12-
ui(new Ui::RandNum)
10+
RandNum::RandNum(QWidget *parent)
11+
: QWidget(parent)
12+
, ui(new Ui::RandNum)
1313
{
1414
ui->setupUi(this);
1515

@@ -39,14 +39,13 @@ void RandNum::on_pushButtonGen_clicked()
3939
int ret = RAND_bytes(buf, sizeof(buf));
4040
if (ret == 0) {
4141
outputNum->setText(QString("生成失败请重试!"));
42-
}
43-
else {
42+
} else {
4443
QString res = QString::asprintf("%02X ", buf[0]);
4544
for (int i = 1; i < randNumByte; ++i) {
4645
res += QString::asprintf("%02X ", buf[i]);
4746
}
4847
outputNum->setText(res);
4948
}
5049

51-
delete [] buf;
50+
delete[] buf;
5251
}

0 commit comments

Comments
 (0)