Reorganizing paths

This commit is contained in:
Adsooi 2024-09-30 00:23:39 +02:00
parent e9d204daab
commit 34cb856dd4
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
249 changed files with 118 additions and 294 deletions

44
common/test/mock/fs.mjs Normal file
View file

@ -0,0 +1,44 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { readFileSync as readNode } from "node:fs"
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url))
export const HOME = "/home/user"
export const TMP = "/tmp"
const filesystem = {
[`${HOME}/test1.lpf`]: readNode(__dirname + "/../../../ci/test1.lpf")
}
export function existsSync(file) {
return filesystem[file] !== undefined
}
export function writeFileSync(file, data, encoding) {
filesystem[file] = Buffer.from(data, encoding)
}
export function readFileSync(file, encoding) {
return filesystem[file].toString(encoding)
}

158
common/test/mock/helper.mjs Normal file
View file

@ -0,0 +1,158 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { readFileSync, writeFileSync, existsSync } from "./fs.mjs"
const DEFAULT_SETTINGS = {
"check_for_updates": true,
"reset_redo_stack": true,
"last_install_greet": "0",
"enable_latex": false,
"expression_editor": {
"autoclose": true,
"colorize": true,
"color_scheme": 0
},
"autocompletion": {
"enabled": true
},
"default_graph": {
"xzoom": 100,
"yzoom": 10,
"xmin": 5 / 10,
"ymax": 25,
"xaxisstep": "4",
"yaxisstep": "4",
"xlabel": "",
"ylabel": "",
"linewidth": 1,
"textsize": 18,
"logscalex": true,
"showxgrad": true,
"showygrad": true
}
}
export class MockHelper {
constructor() {
this.__settings = { ...DEFAULT_SETTINGS }
}
__getSetting(settingName) {
const namespace = settingName.split(".")
let data = this.__settings
for(const name of namespace)
if(data.hasOwnProperty(name))
data = data[name]
else
throw new Error(`Setting ${namespace} does not exist.`)
return data
}
__setSetting(settingName, value) {
const namespace = settingName.split(".")
const finalName = namespace.pop()
let data = this.__settings
for(const name of namespace)
if(data.hasOwnProperty(name))
data = data[name]
else
throw new Error(`Setting ${namespace} does not exist.`)
data[finalName] = value
}
/**
* Gets a setting from the config
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
* @returns {boolean} Value of the setting
*/
getSettingBool(settingName) {
return this.__getSetting(settingName) === true
}
/**
* Gets a setting from the config
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
* @returns {number} Value of the setting
*/
getSettingInt(settingName) {
return +(this.__getSetting(settingName))
}
/**
* Gets a setting from the config
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
* @returns {string} Value of the setting
*/
getSetting(settingName) {
return this.__getSetting(settingName).toString()
}
/**
* Sets a setting in the config
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
* @param {boolean} value
*/
setSettingBool(settingName, value) {
return this.__setSetting(settingName, value === true)
}
/**
* Sets a setting in the config
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
* @param {number} value
*/
setSettingInt(settingName, value) {
return this.__setSetting(settingName, +(value))
}
/**
* Sets a setting in the config
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
* @param {string} value
*/
setSetting(settingName, value) {
return this.__setSetting(settingName, value.toString())
}
/**
* Sends data to be written
* @param {string} file
* @param {string} dataToWrite - just JSON encoded, requires the "LPFv1" mime to be added before writing
*/
write(file, dataToWrite) {
writeFileSync(file, "LPFv1" + dataToWrite)
}
/**
* Requests data to be read from a file
* @param {string} file
* @returns {string} the loaded data - just JSON encoded, requires the "LPFv1" mime to be stripped
*/
load(file) {
if(existsSync(file)) {
const data = readFileSync(file, "utf8")
if(data.startsWith("LPFv1"))
return data.substring(5)
else
throw new Error(`Invalid LogarithmPlotter file.`)
} else
throw new Error(`File not found.`)
}
}

View file

@ -0,0 +1,90 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { TMP, existsSync, writeFileSync } from "./fs.mjs"
const PIXEL = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR4AWNgAAAAAgABc3UBGAAAAABJRU5ErkJggg=="
export class MockLatex {
constructor() {
}
/**
* Creates a simple string hash.
* @param {string} string
* @return {number}
* @private
*/
__hash(string) {
let hash = 0
let i, chr
if(string.length === 0) return hash
for(i = 0; i < string.length; i++) {
chr = string.charCodeAt(i)
hash = ((hash << 5) - hash) + chr
hash |= 0 // Convert to 32bit integer
}
return hash
}
/**
*
* @param {string} markup
* @param {number} fontSize
* @param {string} color
* @return {string}
* @private
*/
__getFileName(markup, fontSize, color) {
const name = this.__hash(`${markup}_${fontSize}_${color}`)
return `${TMP}/${name}.png`
}
/**
* @param {string} markup - LaTeX markup to render
* @param {number} fontSize - Font size (in pt) to render
* @param {string} color - Color of the text to render
* @returns {string} - Comma separated data of the image (source, width, height)
*/
render(markup, fontSize, color) {
const file = this.__getFileName(markup, fontSize, color)
writeFileSync(file, PIXEL, "base64")
return `${file},1,1`
}
/**
* @param {string} markup - LaTeX markup to render
* @param {number} fontSize - Font size (in pt) to render
* @param {string} color - Color of the text to render
* @returns {string} - Comma separated data of the image (source, width, height)
*/
findPrerendered(markup, fontSize, color) {
const file = this.__getFileName(markup, fontSize, color)
if(existsSync(file))
return `${file},1,1`
return ""
}
/**
* Checks if the Latex installation is valid
* @returns {boolean}
*/
checkLatexInstallation() {
return true // We're not *actually* doing any latex.
}
}

60
common/test/mock/qt.mjs Normal file
View file

@ -0,0 +1,60 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Mock qt methods.
/**
* Polyfill for Qt.rect.
* @param {number} x
* @param {number} y
* @param {number} width
* @param {number} height
* @returns {{x, width, y, height}}
*/
function rect(x, y, width, height) {
return { x, y, width, height }
}
/**
* Mock for QT_TRANSLATE_NOOP and qsTranslate
* @param {string} category
* @param {string} string
* @return {string}
*/
function QT_TRANSLATE_NOOP(category, string) {
return string
}
function setup() {
globalThis.Qt = {
rect
}
globalThis.QT_TRANSLATE_NOOP = QT_TRANSLATE_NOOP
globalThis.qsTranslate = QT_TRANSLATE_NOOP
String.prototype.arg = function() { return this; } // No need to reimplement it for now.
}
setup()
export default {
rect,
QT_TRANSLATE_NOOP,
qtTranslate: QT_TRANSLATE_NOOP,
}